Registry / devops / babel-globals-module-formatter

babel-globals-module-formatter

JSON →
library0.1.4jsnpmunverified

A babel plugin/module formatter that transforms ES6 module exports into global variable assignments. Version 0.1.4 is the latest stable release (low cadence, no updates since 2016). It provides a way to use ES6 modules in non-module environments by exposing exports on the global object. Works with Babel 5.x only; not compatible with Babel 6+ due to API changes. Key differentiator: simple, lightweight solution for legacy browser bundles without module loaders.

npm install babel-globals-module-formatter
INSTALL
IMPORT
SIG · BABEL-GLOBALS-MODU
B
babel-globals-module-formatter
devopsjavascriptv0.1.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default
import globalsFormatter from 'babel-globals-module-formatter'
var globalsFormatter = require('babel-globals-module-formatter')
Package has a default export. require() works in Node but may cause issues with Babel transforms.
N/A
Use via babel options: { modules: globalsFormatter }
Directly calling the formatter as a function
Intended to be passed as the 'modules' option in Babel 5 configuration, not invoked directly.

Shows configuration for Babel 5 to use the formatter and how ES6 exports become globals.

// Install: npm install babel@5 babel-globals-module-formatter // .babelrc { "modules": "babel-globals-module-formatter" } // Input (app.js): import { foo } from './utils'; foo(); // Output (transpiled): // (function(global) { // "use strict"; // var _utils = require('./utils'); // global.foo = _utils.foo; // foo(); // })(typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : this);
Debug
Known issues
deprecatedPackage is deprecated: Babel 5 is obsolete, this plugin does not support Babel 6+.
fix
Migrate to Babel 6+ with @babel/plugin-transform-modules-umd or similar.
affects: >=0.0.0
breakingIncompatible with Babel 6+ API changes (modules option replaced by plugins/presets).
fix
Use Babel 5 or switch to a different module formatter for global exports.
affects: >=0.0.0
gotchaDoes not handle circular dependencies: thrown into infinite loop.
fix
Avoid circular dependencies when using this formatter.
affects: >=0.0.0
gotchaOnly works with module systems that use CommonJS require() internally; not compatible with ES module syntax directly unless transpiled.
fix
Ensure Babel already converts ES imports to CommonJS before applying this formatter.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Cannot call a class as a function
Trying to use formatter as a regular function instead of configuring it via babel options.
fix
Set it as the value for 'modules' in Babel 5 .babelrc (e.g., { "modules": "babel-globals-module-formatter" }).
Error: Unknown option: base.base.moduleFormatter
Using Babel 6+ API where formatter is not supported.
fix
Use Babel 5 or a different plugin for global export.
Upgrade
Version history
0.1.4latest on npm
Audit
Dependencies
babel-corerequiredRequires Babel 5.x as a peer dependency (not compatible with Babel 6+)
Agent activity
10 hits · last 30 days
node
8
Amazon
1
Resources
babel-globals-module-formatter — npm install babel-globals-module-formatter · libregistry