Problem with CesiumTerrainProvider in NodeJS applications


I got an error, when i tried to create instance of CesiumTerrainProvider in my node.js app. When i start my app here comes an error:
"An error occurred in "CesiumTerrainProvider": An error occurred while accessing"
I installed CesiumJS via npm: npm install cesium.

There is code of my app:

(function () {

    var express = require('express');
    var compression = require('compression');
    var app = express();

    var bodyParser = require('body-parser')
    app.use(bodyParser.json()); // to support JSON-encoded bodies
    app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
        extended: true

    var Cesium = require(‘cesium’);
    var terrainProvider = new Cesium.CesiumTerrainProvider({
        url: ‘’,
        requestVertexNormals: true

    var underscore = require('underscore');

    console.log("Start");'/', function (req, res) {
        var request = req.body, response = {};
        console.log("Requested positions", request.positions);

    var server = app.listen(3000, function () {
        var port = server.address().port;
        console.log('Aegis-Server listening at port %s', port);

Changing url to http:// or // doesnt help.

Unfortunately, not all Cesium objects work under Node (as Cesium is primarily a client-side browser library). In this case I believe the problem is the use of XmlHttpRequest (which does not exist in Node). We could detect this and fallback to the npm request module, but no one is actively working on that. We’d be happy to look at any pull requests that try and improve Node compatibility.

Thanks for fast response. I will try to improve Node compatibility of CesiumJS.

I know this is an old thread, but I am seeing the same error: "An error occurred in “CesiumTerrainProvider”: An error occurred while accessing" when I instantiate new Cesium.CesiumTerrainProvider({url : ‘’}).

Is this still an issue or do you guys now have a workaround for this problem?

Thank you very much,


Hello Ricardo,

Thanks for finding this issue. I don’t believe anyone has worked on a workaround for the problem yet.

You could follow Matt’s suggestion and modify this function to use request if XmlHttpRequest doesn’t exist:

See our Build Guide for instructions on checking out and building the code:



My current workaround is to use PhantomJS instead of node for this purpose. In order to enable PhantomJS xmlhttprequest to work with a remote service like this one, you need to invoke with command line options as follows: phantomjs --local-to-remote-url-access=true --web-security=false yoursampleterrainscript.js

When I get some time I can try and modify the function and submit a PR.

Thanks again,


Hi Hannah

I submitted a PR today for this issue. I hope it is acceptable to you.

Thank you,