babel-plugin-remove-webpack
raw JSON → 1.1.0 verified Sat Apr 25 auth: no javascript maintenance
Babel plugin that removes webpack-specific functions (require.ensure, require.include) from JavaScript code, useful for running universal JavaScript on the server without shims. Version 1.1.0 is the latest and only stable release, with low maintenance cadence (last update years ago). Unlike manual polyfills, this plugin automatically strips webpack code at the AST level, enabling server-side execution without code splitting. For Node.js environments with babel-register, it avoids defining dummy functions per file. Not for use in webpack builds, as it would disable code splitting.
Common errors
error Cannot find module 'babel-plugin-remove-webpack' ↓
cause Missing npm install or wrong working directory.
fix
Run 'npm install babel-plugin-remove-webpack --save-dev' and ensure node_modules is accessible.
error TypeError: Cannot read property 'ensure' of undefined ↓
cause Plugin not applied or not working; require.ensure remains in code.
fix
Check Babel config includes 'remove-webpack' in plugins, and that the transform runs before execution.
Warnings
gotcha Do not use this plugin in webpack builds; it will remove code splitting. ↓
fix Only apply in server-side Babel transforms, not in webpack configuration.
deprecated require.ensure is deprecated in webpack in favor of dynamic import(). This plugin does not handle dynamic imports. ↓
fix Use dynamic import() on modern webpack and consider a different plugin for that case.
gotcha Plugin is CJS-only; no ESM export. Cannot import via import statement. ↓
fix Use require() in Babel config or transform.
Install
npm install babel-plugin-remove-webpack yarn add babel-plugin-remove-webpack pnpm add babel-plugin-remove-webpack Imports
- default wrong
import plugin from 'babel-plugin-remove-webpack'correctmodule.exports = require('babel-plugin-remove-webpack')
Quickstart
// Install: npm install --save-dev babel-plugin-remove-webpack
// In .babelrc or babel.config.js:
{
"plugins": ["remove-webpack"]
}
// With babel-register in your server entry:
require('@babel/register')({ plugins: ['remove-webpack'] });
require('./client-code'); // will run without require.ensure/require.include
// Or programmatically:
const babel = require('@babel/core');
const result = babel.transform(
`require.ensure(['a'], function(r) { r('a'); });`,
{ plugins: ['remove-webpack'] }
);
console.log(result.code); // (function () { require('a'); })();