A Babel plugin (v0.1.9) that fixes the default import interoperability issue when importing simulated ESM (CommonJS modules with __esModule flag) from native ES modules in Node.js. This plugin automatically wraps export values to ensure default imports work correctly. Compared to alternatives, it automates the wrapping process. Maintained by qnighy, with releases as needed. Also available as swc-plugin-node-cjs-interop for SWC users.
npm install babel-plugin-node-cjs-interopVerified import paths — ran on the pinned version, not inferred.
Shows how to install and configure the Babel plugin to fix default import interoperability with native ES modules.
Manually wrap re-exported modules or avoid re-exports from simulated ESM packages.
Be aware that importing mutable exports from simulated ESM may behave differently. Test thoroughly.
Ensure all named exports exist in the imported package. Use TypeScript or check package exports.
Limit the packages list to only those experiencing issues. Consider using node-cjs-interop-finder to detect problematic packages.
Manually verify affected packages and test imports.
Add the problematic package to babel-plugin-node-cjs-interop's packages list. Example: packages: ['styled-components']
Use babel-plugin-node-cjs-interop with the package name listed in the configuration.