{"id":19188,"library":"babel-plugin-transform-dynamic-import","title":"babel-plugin-transform-dynamic-import","description":"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.","status":"active","version":"2.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/airbnb/babel-plugin-dynamic-import-node","tags":["javascript","babel","plugin","dynamic","import","node"],"install":[{"cmd":"npm install babel-plugin-transform-dynamic-import","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-transform-dynamic-import","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-transform-dynamic-import","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required peer dependency for Babel plugin functionality","package":"@babel/core","optional":true}],"imports":[{"note":"Plugin is typically used in Babel config as a string, but when importing programmatically, use default import.","wrong":"const plugin = require('babel-plugin-transform-dynamic-import')","symbol":"default","correct":"import plugin from 'babel-plugin-transform-dynamic-import'"},{"note":"The visitor object is exported for advanced usage, e.g., composing plugins.","wrong":"import { default } from 'babel-plugin-transform-dynamic-import'","symbol":"visitor","correct":"import { visitor } from 'babel-plugin-transform-dynamic-import'"},{"note":"TypeScript type for plugin options, available since v2.1.0.","wrong":"","symbol":"PluginConfig","correct":"import type { PluginConfig } from 'babel-plugin-transform-dynamic-import'"}],"quickstart":{"code":"// .babelrc\n{\n  \"plugins\": [\"transform-dynamic-import\"]\n}\n\n// input.js\nasync function loadModule() {\n  const { default: module } = await import('./module');\n  return module;\n}\n\n// output.js (transpiled for Node)\nfunction loadModule() {\n  return Promise.resolve().then(function () {\n    return _interopRequireWildcard(require('./module'));\n  });\n}","lang":"javascript","description":"Configures Babel to transform dynamic import() into deferred require() calls for Node.js."},"warnings":[{"fix":"Upgrade @babel/core to version 7.0.0 or later.","message":"The plugin no longer supports @babel/core versions below 7.0.0 as of v2.0.0.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Remove the option from plugin configuration.","message":"Option 'allowTopLevelThis' has been deprecated in v2.1.0.","severity":"deprecated","affected_versions":">=2.1.0"},{"fix":"Use @babel/plugin-transform-modules-commonjs alongside this plugin for full CommonJS transformation.","message":"Dynamic 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.","severity":"gotcha","affected_versions":"all"},{"fix":"Use with Webpack or Parcel that handle dynamic imports natively, or include a polyfill like dynamic-import-polyfill.","message":"The 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.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Add 'transform-dynamic-import' to your Babel plugins list.","cause":"Missing or misconfigured Babel plugin for dynamic imports.","error":"SyntaxError: Support for the experimental syntax 'import()' isn't currently enabled"},{"fix":"Upgrade @babel/core to version >=7.0.0.","cause":"Using the plugin with an older version of @babel/core that doesn't support the visitor.","error":"TypeError: (intermediate value)(...) is not a function"},{"fix":"Run 'npm install babel-plugin-transform-dynamic-import --save-dev'","cause":"Plugin not installed or not in node_modules.","error":"Error: Cannot find module 'babel-plugin-transform-dynamic-import'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}