{"id":19197,"library":"babel-plugin-transform-globalthis","title":"babel-plugin-transform-globalthis","description":"Babel plugin that transforms `globalThis` references to a ponyfill detecting the runtime environment (window, self, global, or fallback object). Version 1.0.0 released Jan 2021; single stable release with no further updates. Differentiates from @babel/plugin-transform-global-this by not relying on core-js and providing a lighter-weight transformation. Suitable for environments where globalThis is unsupported or for projects that prefer explicit polyfilling via Babel transpilation.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/niksy/babel-plugin-transform-globalthis","tags":["javascript","babel","globalthis","plugin","transform","window","global","self"],"install":[{"cmd":"npm install babel-plugin-transform-globalthis","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-transform-globalthis","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-transform-globalthis","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for plugin integration","package":"@babel/core","optional":false}],"imports":[{"note":"CJS only; no ESM export. Use require() in .babelrc.js or babel.config.js.","wrong":"import plugin from 'babel-plugin-transform-globalthis';","symbol":"default","correct":"module.exports = require('babel-plugin-transform-globalthis');"},{"note":"Full npm package name required in .babelrc or babel.config.json; shorthand not supported.","wrong":"\"plugins\": [\"transform-globalthis\"]","symbol":"plugin name string","correct":"\"plugins\": [\"babel-plugin-transform-globalthis\"]"}],"quickstart":{"code":"// Install: npm install --save-dev babel-plugin-transform-globalthis\n// .babelrc\n{\n  \"plugins\": [\"babel-plugin-transform-globalthis\"]\n}\n// Input\nconst x = globalThis.Math;\n// Output (ES5-compatible ponyfill)\nvar _globalThis = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : typeof global !== 'undefined' ? global : {};\nvar x = _globalThis.Math;","lang":"javascript","description":"Shows basic setup using .babelrc and transformation of globalThis to a runtime-detected global object."},"warnings":[{"fix":"Use @babel/plugin-transform-global-this or core-js for shared polyfill; or use module-level plugin to avoid duplication.","message":"Plugin uses RUNTIME ponyfill inserted inline, not a shared module. Increases bundle size if globalThis used in many files.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure all cross-environment code uses globalThis explicitly; the plugin does not transform window, self, or global.","message":"Transformation is applied only to direct globalThis references; not to property accesses on global objects like window.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Accept the generated variable name; or fork the plugin to add configuration.","message":"No option to customize the ponyfill variable name; always uses _globalThis.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use module.exports or .babelrc JSON format; e.g., module.exports = { plugins: ['babel-plugin-transform-globalthis'] };","cause":"Using ESM import syntax in .babelrc.js or babel.config.js while plugin is CJS","error":"SyntaxError: Unexpected token 'export'"},{"fix":"Ensure Babel is configured to run on the file where globalThis appears; add plugin to .babelrc or babel.config.json.","cause":"Plugin not applied (transpilation skipped or Babel not configured)","error":"ReferenceError: globalThis is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}