
Product
Secure Your AI-Generated Code with Socket MCP
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
babel-plugin-transform-import-commonjs
Advanced tools
Transform ES2015 import to CommonJS require
Fork of https://github.com/kiurchv/babel-plugin-transform-system-import-commonjs that compiles import
instead of System.import
, now that the import()
proposal has been accepted.
Babel plugin that transforms ES2015 import into CommonJS require.
https://github.com/tc39/proposal-dynamic-import
This plugin transforms
var myModule = "./path/to/myModule";
import(myModule).then(function (module) {
console.log(module);
});
to
var myModule = "./path/to/myModule";
new Promise(function(resolve) {
resolve(require(myModule));
}.bind(this)).then(function (module) {
console.log(module);
});
You need support for Promise, use polyfill if needed.
$ npm install babel-plugin-transform-import-commonjs
.babelrc
(Recommended).babelrc
{
"plugins": ["transform-import-commonjs"]
}
$ babel --plugins transform-import-commonjs script.js
require("babel-core").transform("code", {
plugins: ["transform-import-commonjs"]
});
FAQs
Transform ES2015 import to CommonJS require
The npm package babel-plugin-transform-import-commonjs receives a total of 9 weekly downloads. As such, babel-plugin-transform-import-commonjs popularity was classified as not popular.
We found that babel-plugin-transform-import-commonjs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.