{"id":19046,"library":"babel-plugin-dynamic-import-node-sync","title":"babel-plugin-dynamic-import-node-sync","description":"Babel 7 plugin that transpiles dynamic import() expressions to synchronous require() calls for Node.js, primarily used for server-side rendering. Current stable version is 2.0.1, with a single release on Babel 7. Unlike the alternative babel-plugin-dynamic-import-node which wraps require() in Promise.resolve().then(), this plugin outputs a direct synchronous require(), eliminating the Promise wrapper. It matches the proposed import() spec. Installation via npm, configuration via .babelrc or CLI. Designed for Node.js environments where synchronous module loading is acceptable.","status":"active","version":"2.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/seeden/babel-plugin-dynamic-import-node-sync","tags":["javascript","babel","plugin","dynamic","import","node","sync","ssr","react-router"],"install":[{"cmd":"npm install babel-plugin-dynamic-import-node-sync","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-dynamic-import-node-sync","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-dynamic-import-node-sync","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required by Babel for parsing dynamic import syntax; not a direct dependency but typically needed in Babel config.","package":"@babel/plugin-syntax-dynamic-import","optional":true}],"imports":[],"quickstart":{"code":"// .babelrc\n{\n  \"plugins\": [\"dynamic-import-node-sync\"]\n}\n\n// code.js\nasync function loadModule() {\n  const module = await import('./mymodule');\n  return module.default;\n}\n\n// compiles to:\nfunction loadModule() {\n  const module = require('./mymodule');\n  return module.default;\n}","lang":"javascript","description":"Demonstrates installation and usage: configuration in .babelrc and compilation result showing import() converted to require()."},"warnings":[{"fix":"Ensure that the imported module does not rely on asynchronous operations for initialization; use only for modules that are safe to load synchronously, typically local modules or statically analyzable dependencies.","message":"This plugin replaces dynamic import() with require() making it synchronous. If the module has side-effects that expect asynchronous behavior (e.g., network requests), they will execute synchronously and block the event loop.","severity":"gotcha","affected_versions":">=2.0"},{"fix":"Ensure all imported modules are CommonJS-compatible or transpiled with @babel/plugin-transform-modules-commonjs before using this plugin. Alternatively, use babel-plugin-dynamic-import-node if you need asynchronous behavior.","message":"The plugin transpiles import() to require() regardless of whether the module is ESM or CJS. For ESM modules, require() may fail if the module is not properly compiled to CommonJS or if it uses top-level await.","severity":"gotcha","affected_versions":">=2.0"},{"fix":"Use babel-plugin-dynamic-import-webpack or other browser-compatible dynamic import plugins for client-side code.","message":"This plugin is designed for Node.js server-side rendering only. Do not use in browser bundles, as require() is not available in browsers.","severity":"gotcha","affected_versions":">=2.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run npm install --save-dev @babel/core","cause":"Missing Babel core package.","error":"Error: Cannot find module '@babel/core'"},{"fix":"Upgrade to @babel/core 7.x or use version 1.0.1 of this plugin for Babel 6.","cause":"Using Babel 6 core with a Babel 7 plugin.","error":"Error: Requires Babel \"7.0.0-0\" but \"@babel/core\" is \"6.x\"."},{"fix":"Add '@babel/plugin-syntax-dynamic-import' to your Babel plugins list, or rely on @babel/preset-env which includes it.","cause":"Babel is not configured to parse dynamic imports; missing plugin-syntax-dynamic-import.","error":"SyntaxError: Unexpected token import"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}