Registry / serialization / babel-plugin-transform-globalthis

babel-plugin-transform-globalthis

JSON →
library1.0.0jsnpmunverified

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.

npm install babel-plugin-transform-globalthis
INSTALL
IMPORT
SIG · BABEL-PLUGIN-TRANS
B
babel-plugin-transform-globalthis
serializationjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
module.exports = require('babel-plugin-transform-globalthis');
import plugin from 'babel-plugin-transform-globalthis';
CJS only; no ESM export. Use require() in .babelrc.js or babel.config.js.
plugin name string
"plugins": ["babel-plugin-transform-globalthis"]
"plugins": ["transform-globalthis"]
Full npm package name required in .babelrc or babel.config.json; shorthand not supported.

Shows basic setup using .babelrc and transformation of globalThis to a runtime-detected global object.

// Install: npm install --save-dev babel-plugin-transform-globalthis // .babelrc { "plugins": ["babel-plugin-transform-globalthis"] } // Input const x = globalThis.Math; // Output (ES5-compatible ponyfill) var _globalThis = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : typeof global !== 'undefined' ? global : {}; var x = _globalThis.Math;
Debug
Known issues
gotchaPlugin uses RUNTIME ponyfill inserted inline, not a shared module. Increases bundle size if globalThis used in many files.
fix
Use @babel/plugin-transform-global-this or core-js for shared polyfill; or use module-level plugin to avoid duplication.
affects: >=1.0.0
gotchaTransformation is applied only to direct globalThis references; not to property accesses on global objects like window.
fix
Ensure all cross-environment code uses globalThis explicitly; the plugin does not transform window, self, or global.
affects: >=1.0.0
gotchaNo option to customize the ponyfill variable name; always uses _globalThis.
fix
Accept the generated variable name; or fork the plugin to add configuration.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: Unexpected token 'export'
Using ESM import syntax in .babelrc.js or babel.config.js while plugin is CJS
fix
Use module.exports or .babelrc JSON format; e.g., module.exports = { plugins: ['babel-plugin-transform-globalthis'] };
ReferenceError: globalThis is not defined
Plugin not applied (transpilation skipped or Babel not configured)
fix
Ensure Babel is configured to run on the file where globalThis appears; add plugin to .babelrc or babel.config.json.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
@babel/corerequiredPeer dependency for plugin integration
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
babel-plugin-transform-globalthis — npm install babel-plugin-transform-globalthis · libregistry