babel-plugin-transform-es2015-modules-strip
raw JSON → 0.1.3 verified Sat Apr 25 auth: no javascript deprecated
A Babel plugin that strips ES2015 import/export statements from JavaScript modules. Current version 0.1.3, last released as prerelease-only (no stable release after). This plugin was used by Bootstrap v4.0.0-beta through v4.1.2 to remove module syntax without bundling. It is an alternative to @babel/plugin-transform-modules-commonjs for code that is already concatenated or bundled by other tools. Requires modules: false in @babel/preset-env. Unmaintained since 2018.
Common errors
error Error: Cannot find module 'babel-plugin-transform-es2015-modules-strip' ↓
cause Plugin not installed or not in node_modules.
fix
Run 'npm install --save-dev babel-plugin-transform-es2015-modules-strip'.
error Error: [BABEL] input.js: Unknown plugin "transform-es2015-modules-strip" specified in "..." ↓
cause Babel cannot resolve the plugin; possibly not installed or misnamed.
fix
Ensure plugin is installed and use the correct short name without 'babel-plugin-' prefix.
error SyntaxError: Unexpected token import ↓
cause Babel is not configured to handle ES modules before this plugin runs.
fix
Add '@babel/preset-env' with modules: false to your Babel config.
Warnings
deprecated This package is unmaintained and has no stable release. Last version 0.1.3 was published as a prerelease but no 1.0.0 was released. ↓
fix Consider using a modern approach: if you need to strip imports, use @babel/plugin-transform-modules-commonjs with modules: false? Actually, modules: false already removes module syntax. This plugin is redundant when modules: false in preset-env. If you need to strip imports for bundling, use a bundler like Rollup or Webpack.
breaking Requires @babel/preset-env with modules: false; otherwise import/export statements are transformed by preset-env before this plugin runs, causing unexpected behavior. ↓
fix Always set modules: false in @babel/preset-env when using this plugin.
gotcha Plugin name in Babel config should omit 'babel-plugin-' prefix. Using full name works but is non-standard. ↓
fix Use 'transform-es2015-modules-strip' as the plugin name.
gotcha This plugin only strips import/export statements; it does not resolve module dependencies. If you use imported variables in the code, they will remain undeclared after stripping. ↓
fix Ensure that the imported variables are either removed manually or are defined elsewhere (e.g., via a global script or concatenation).
Install
npm install babel-plugin-transform-es2015-modules-strip yarn add babel-plugin-transform-es2015-modules-strip pnpm add babel-plugin-transform-es2015-modules-strip Imports
- default
import plugin from 'babel-plugin-transform-es2015-modules-strip' - babel-plugin wrong
plugins: ['babel-plugin-transform-es2015-modules-strip']correctplugins: ['transform-es2015-modules-strip'] - require wrong
var strip = require('babel-plugin-transform-es2015-modules-strip'); require('@babel/core').transformSync(code, { plugins: [strip] })correctrequire('@babel/core').transformSync(code, { plugins: ['transform-es2015-modules-strip'] })
Quickstart
// Install: npm install --save-dev @babel/core @babel/preset-env babel-plugin-transform-es2015-modules-strip
// babel.config.json
{
"presets": [
["@babel/preset-env", {
"modules": false
}]
],
"plugins": ["transform-es2015-modules-strip"]
}
// Input file: input.js
import path from 'path';
console.log(path.sep);
export default 42;
// Run: npx babel input.js --out-file output.js
// Output file: output.js
console.log(path.sep);