Search code examples
javascriptrequirejsweb-workercesiumjs

Error in cesiumWorkerBootstrapper when it use RequireJS importScripts


I encountered a problem when using cesium with openlayer. When trying to display a 3D map, the following error occurs:

Uncaught Error: importScripts failed for Workers/createVerticesFromQuantizedTerrainMesh at http://localhost:5866/Scripts/lib/openlayers/Cesium/Workers/createVerticesFromQuantizedTerrainMesh.js
http://requirejs.org/docs/errors.html#importscripts
    at makeError (cesiumWorkerBootstrapper.js:formatted:102)
    at Function.req.load (cesiumWorkerBootstrapper.js:formatted:805)
    at Object.load (cesiumWorkerBootstrapper.js:formatted:697)
    at b.load (cesiumWorkerBootstrapper.js:formatted:381)
    at b.fetch (cesiumWorkerBootstrapper.js:formatted:370)
    at b.check (cesiumWorkerBootstrapper.js:formatted:422)
    at b.enable (cesiumWorkerBootstrapper.js:formatted:519)
    at Object.enable (cesiumWorkerBootstrapper.js:formatted:649)
    at b.<anonymous> (cesiumWorkerBootstrapper.js:formatted:512)
    at cesiumWorkerBootstrapper.js:formatted:83

The code I use is as follows:

that.ol3d = new olcs.OLCesium({
                    map: that.map
                });

                scene = that.ol3d.getCesiumScene();

                Cesium.Ion.defaultAccessToken = 'my-token';
                scene.terrainProvider = new Cesium.CesiumTerrainProvider({
                    url: Cesium.IonResource.fromAssetId(1)
                });

And then:

if (that.ol3d) {
                that.ol3d.setEnabled(true);
                that.isActivate = true;
               }

Cesium is downloaded to the localhost (located on my PC).

Studying the problem, I found that exception occurs inside the cesiumWorkerBootstrapper.js on the line importScripts(i).

try {
    importScripts(i),
    e.completeLoad(t)
} catch (r) {
    e.onError(makeError("importscripts", "importScripts failed for " + t + " at " + i, r, [t]))
}

The interesting thing is that this code worked before. Now stopped. But if I connect the cesium with , the system starts working again.

I would be grateful for any help.


Solution

  • I have found a solution. The problem was that the server was returning a worker with the wrong Response headers. Content-Type mattered "js; charset=UTF-8" instead of "javascript/application; charset=UTF-8". I change the server configuration and it worked. enter image description here