karatelabs/karate · error · Error
Unable to resolve global `this`
Error message
Unable to resolve global `this`
What it means
resemble.js needs a reference to the JS global object to function, and this fallback resolver checks `self` and `window` before giving up. It throws when the script runs in a non-DOM environment (e.g. a bare Node worker, older runtime without globalThis) where neither global exists. It indicates the environment cannot host this browser-oriented library.
Solutions
- Run in a real browser context or update Node to >= 12 so `globalThis` exists
- Polyfill the global before loading: `(0,eval)('this').globalThis = ...` or use a shim like `global-this`
- Do not import resemble.js in server-side code; use a JVM/native image-diff library instead
Example fix
// before (Node 10, no globalThis/window/self)
require('./resemble.js');
// after
if (typeof globalThis === 'undefined') { globalThis = require('global-this'); }
require('./resemble.js'); Defensive patterns
Strategy: validation
When it happens
Trigger: Loading resemble.js in an environment where `self`, `window`, and `globalThis` are all undefined — e.g. a plain Node < 12 runtime, a web worker context stripped of globals, or server-side evaluation of the static asset.
Common situations: Serving karate-ext static assets into a Node-based screenshot/diff runner on an old Node version; bundling resemble.js for server-side use instead of browser use.
Understand the failure class
Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.
Related errors
- Invalid ignore
- karate-boot.js evaluation failed
- Dynamic expression must return a list or function
- Failed to evaluate dynamic expression
- doc() requires 'read' key with template path
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/51c55b233b4af169.
Report an issue: GitHub.
Appendix: source
Thrown at karate-image/src/main/resources/META-INF/karate-ext/static/resemble.js:14
/*
James Cryer / Huddle
URL: https://github.com/Huddle/Resemble.js
*/
var naiveFallback = function () {
// ISC (c) 2011-2019 https://github.com/medikoo/es5-ext/blob/master/global.js
if (typeof self === "object" && self) {
return self;
}
if (typeof window === "object" && window) {
return window;
}
throw new Error("Unable to resolve global `this`");
};
var getGlobalThis = function () {
// ISC (c) 2011-2019 https://github.com/medikoo/es5-ext/blob/master/global.js
// Fallback to standard globalThis if available
if (typeof globalThis === "object" && globalThis) {
return globalThis;
}
try {
Object.defineProperty(Object.prototype, "__global__", {
get: function () {
return this;
},
configurable: true
});
} catch (error) {
return naiveFallback();View on GitHub (pinned to a22eb90246)