A Babel plugin that transforms CommonJS require() calls into ES6 import statements. Version 1.1.0 is the latest stable release. It converts patterns like var a = require('a') to import a from 'a'. This plugin is useful for incremental migration of codebases from CommonJS to ES modules. It operates as a Babel plugin and requires babel-core (or @babel/core) to function. Unlike more comprehensive tools like @babel/plugin-transform-modules-commonjs, this plugin focuses solely on require-to-import conversion without handling exports. The package has a slow release cadence and is minimal in scope.
npm install babel-plugin-transform-requireVerified import paths — ran on the pinned version, not inferred.
Shows how to transform a require call to an import statement using the plugin programmatically with babel-core.
Use additional plugins like @babel/plugin-transform-modules-commonjs for a full CJS-to-ESM conversion.
Manually refactor dynamic requires or use a runtime helper for dynamic imports.
Manually adjust code to use let or const and ensure no reassignment of imported bindings.
Run npm install --save-dev babel-core (or @babel/core for Babel 7+).
Use a more modern plugin or migrate to @babel/plugin-transform-modules-commonjs.
Run npm install --save-dev babel-core (or @babel/core) to install babel-core as a development dependency.
Use import transformRequire from 'babel-plugin-transform-require' without curly braces.
Use the plugin to transform the require calls, or ensure that Node.js is configured with --experimental-require-module flag if applicable.
Use a bundler like Webpack or a Node.js version that supports ES modules with --experimental-modules flag.
No dependency data recorded yet.