{"record":{"id":"51c55b233b4af169","repo":"karatelabs/karate","slug":"unable-to-resolve-global-this","errorCode":null,"errorMessage":"Unable to resolve global `this`","messagePattern":"Unable to resolve global `this`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"karate-image/src/main/resources/META-INF/karate-ext/static/resemble.js","lineNumber":14,"sourceCode":"/*\nJames Cryer / Huddle\nURL: https://github.com/Huddle/Resemble.js\n*/\n\nvar naiveFallback = function () {\n    // ISC (c) 2011-2019 https://github.com/medikoo/es5-ext/blob/master/global.js\n    if (typeof self === \"object\" && self) {\n        return self;\n    }\n    if (typeof window === \"object\" && window) {\n        return window;\n    }\n    throw new Error(\"Unable to resolve global `this`\");\n};\n\nvar getGlobalThis = function () {\n    // ISC (c) 2011-2019 https://github.com/medikoo/es5-ext/blob/master/global.js\n    // Fallback to standard globalThis if available\n    if (typeof globalThis === \"object\" && globalThis) {\n        return globalThis;\n    }\n\n    try {\n        Object.defineProperty(Object.prototype, \"__global__\", {\n            get: function () {\n                return this;\n            },\n            configurable: true\n        });\n    } catch (error) {\n        return naiveFallback();","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-image/src/main/resources/META-INF/karate-ext/static/resemble.js#L1-L32","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (Node 10, no globalThis/window/self)\nrequire('./resemble.js');\n// after\nif (typeof globalThis === 'undefined') { globalThis = require('global-this'); }\nrequire('./resemble.js');","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["javascript","environment","image-diff"],"backgroundTag":"unsupported-platform","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}