diff --git a/package.json b/package.json index 03ac09806ab..1a6549f7bb4 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "gl": "^4.0.1", "glob": "^7.0.3", "is-builtin-module": "^1.0.0", - "jsdom": "11.11.0", + "jsdom": "^11.11.0", "json-stringify-pretty-compact": "^1.0.4", "jsonwebtoken": "^8.3.0", "mock-geolocation": "^1.0.11", diff --git a/src/util/window.js b/src/util/window.js index 7019c9650c9..f053734e6ac 100644 --- a/src/util/window.js +++ b/src/util/window.js @@ -38,6 +38,13 @@ function restore(): Window { virtualConsole: new jsdom.VirtualConsole().sendTo(console) }); + // Delete local and session storage from JSDOM and stub them out with a warning log + // Accessing these properties during extend() produces an error in Node environments + // See https://github.com/mapbox/mapbox-gl-js/pull/7455 for discussion + delete window.localStorage; + delete window.sessionStorage; + window.localStorage = window.sessionStorage = () => console.log('Local and session storage not available in Node. Use a stub implementation if needed for testing.'); + window.devicePixelRatio = 1; window.requestAnimationFrame = function(callback) {