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.
npm install babel-plugin-dynamic-import-node-syncNo compatibility data collected yet for this library.
Demonstrates installation and usage: configuration in .babelrc and compilation result showing import() converted to require().
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.
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.
Use babel-plugin-dynamic-import-webpack or other browser-compatible dynamic import plugins for client-side code.
Run npm install --save-dev @babel/core
Upgrade to @babel/core 7.x or use version 1.0.1 of this plugin for Babel 6.
Add '@babel/plugin-syntax-dynamic-import' to your Babel plugins list, or rely on @babel/preset-env which includes it.