Error when switched on Cesium-1.107.1

Dear Cesium users and team!
I have this code in my view3d.html file:

const viewer = new Cesium.Viewer(‘cesiumContainer’, {
imageryProvider: Cesium.createWorldImagery(),
terrainProvider: Cesium.createWorldTerrain(),
scene3DOnly: true,
selectionIndicator: false,
//baseLayerPicker: false

And all worked well. When I switched to Cesium-1.107.1, I got this error message:

view3d:41 Uncaught TypeError: Cesium.createWorldImagery is not a function
at view3d:41:34

No Earth image on stars sky. What does it mean, and what I have to do?
Thanks in advance.


There have been some breaking changes in version 107, and they are described in the change log for version 1.107. Many of them have been related to the handling of promises and asynchronous operations. (Some general information can be found in CesiumJS Ready Promise Deprecation / API Changes , but this is only indirectly related to your question).

Long story short:

  • createWorldImagery was replaced with createWorldImageryAsync
  • createWorldTerrain was replaced with createWorldTerrainAsync

And you have to use await to await the results of these functions:

const viewer = new Cesium.Viewer('cesiumContainer', {
  imageryProvider: await Cesium.createWorldImageryAsync(),
  terrainProvider: await Cesium.createWorldTerrainAsync(),
  scene3DOnly: true,
  selectionIndicator: false,
  //baseLayerPicker: false

(BTW: In most cases, one can just rely on the default imageryProvider and terrainProvider…)

Thank you very much, Marco!

Sorry, but when I have changed
imageryProvider: Cesium.createWorldImagery(),
imageryProvider: await Cesium.createWorldImageryAsync(),
I have got this error message:
Uncaught SyntaxError: Unexpected identifier ‘Cesium’ (at view3d:41:26)


Just to confirm: Does this Sandcastle work for you?

If it works, we’d have to figure out what is different in your environment.

My first guess would be that you try to create the viewer in a context (i.e. in a function) that is not marked as async, but think that this should cause a different error message… (2.3 KB)
This is my .html file.

The await syntax is only valid in “modules”. Although I would have expected the error message to be more explicit here. I cannot immediately try it out based on your HTML file (because I’d have to remove everything that is specific for your setup, e.g. the localhost accesses and so). But I think it should work when you change the beginning of the script from
<script type="module">

Yeees! It solved the problem. Thank you, Marco!