Registry / web-framework / babel-plugin-transform-dynamic-import

babel-plugin-transform-dynamic-import

JSON →
library2.1.0jsnpmunverified

Babel plugin that transpiles dynamic import() expressions to deferred require() calls for Node.js environments. v2.1.0 is the latest stable version, with occasional updates. It matches the proposed spec and requires Babylon >= v6.12.0 to parse dynamic imports correctly. Unlike other Babel dynamic import plugins, this one specifically targets Node.js (not browsers) and defers the require() call to maintain lazy loading semantics.

npm install babel-plugin-transform-dynamic-import
INSTALL
IMPORT
SIG · BABEL-PLUGIN-TRANS
B
babel-plugin-transform-dynamic-import
web-frameworkjavascriptv2.1.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
import plugin from 'babel-plugin-transform-dynamic-import'
const plugin = require('babel-plugin-transform-dynamic-import')
Plugin is typically used in Babel config as a string, but when importing programmatically, use default import.
visitor
import { visitor } from 'babel-plugin-transform-dynamic-import'
import { default } from 'babel-plugin-transform-dynamic-import'
The visitor object is exported for advanced usage, e.g., composing plugins.
PluginConfig
import type { PluginConfig } from 'babel-plugin-transform-dynamic-import'
TypeScript type for plugin options, available since v2.1.0.

Configures Babel to transform dynamic import() into deferred require() calls for Node.js.

// .babelrc { "plugins": ["transform-dynamic-import"] } // input.js async function loadModule() { const { default: module } = await import('./module'); return module; } // output.js (transpiled for Node) function loadModule() { return Promise.resolve().then(function () { return _interopRequireWildcard(require('./module')); }); }
Debug
Known issues
breakingThe plugin no longer supports @babel/core versions below 7.0.0 as of v2.0.0.
fix
Upgrade @babel/core to version 7.0.0 or later.
affects: >=2.0.0
deprecatedOption 'allowTopLevelThis' has been deprecated in v2.1.0.
fix
Remove the option from plugin configuration.
affects: >=2.1.0
gotchaDynamic import() is only transformed to require() for Node.js; in browser targets you need a different plugin like @babel/plugin-syntax-dynamic-import or webpack.
fix
Use @babel/plugin-transform-modules-commonjs alongside this plugin for full CommonJS transformation.
affects: all
gotchaThe plugin does not polyfill dynamic import; it only transforms syntax. If you use dynamic import in browsers without a bundler, you'll get a runtime error.
fix
Use with Webpack or Parcel that handle dynamic imports natively, or include a polyfill like dynamic-import-polyfill.
affects: all
Errors
Common errors & fixes
SyntaxError: Support for the experimental syntax 'import()' isn't currently enabled
Missing or misconfigured Babel plugin for dynamic imports.
fix
Add 'transform-dynamic-import' to your Babel plugins list.
TypeError: (intermediate value)(...) is not a function
Using the plugin with an older version of @babel/core that doesn't support the visitor.
fix
Upgrade @babel/core to version >=7.0.0.
Error: Cannot find module 'babel-plugin-transform-dynamic-import'
Plugin not installed or not in node_modules.
fix
Run 'npm install babel-plugin-transform-dynamic-import --save-dev'
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
@babel/coreoptionalRequired peer dependency for Babel plugin functionality
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
babel-plugin-transform-dynamic-import — npm install babel-plugin-transform-dynamic-import · libregistry