Huge news!Announcing our $20M Series A led by Andreessen Horowitz.Learn more
Socket
Socket
Log inDemoInstall

@babel/plugin-transform-modules-commonjs

Package Overview
Dependencies
54
Maintainers
4
Versions
88
Issues
File Explorer

Advanced tools

Install Socket

Protect your apps from supply chain attacks

Install

@babel/plugin-transform-modules-commonjs

This plugin transforms ES2015 modules to CommonJS

    7.23.3latest
    GitHub
    npm

Version published
Maintainers
4
Weekly downloads
24,365,313
decreased by-0.98%

Weekly downloads

Package description

What is @babel/plugin-transform-modules-commonjs?

The @babel/plugin-transform-modules-commonjs npm package is a Babel plugin that transforms ECMAScript modules to CommonJS modules. This is useful for enabling code written using ES6 module syntax to run in environments that only support CommonJS modules, such as older versions of Node.js or browsers without ES6 module support.

What are @babel/plugin-transform-modules-commonjs's main functionalities?

Transform ES6 import statements to CommonJS require

Converts ES6 import statements into CommonJS require calls.

import { square } from './math';
console.log(square(5));
// Transformed code:
var _math = require('./math');
console.log(_math.square(5));

Transform ES6 export statements to CommonJS exports

Converts ES6 named and default export statements into CommonJS module.exports assignments.

export const square = (n) => n * n;
export default square;
// Transformed code:
const square = (n) => n * n;
exports.square = square;
exports.default = square;

Interoperability with Babel's module interop helpers

Ensures compatibility with Babel's interopRequireDefault helper to handle default exports when importing modules.

import square from './math';
console.log(square(5));
// Transformed code with interopRequireDefault helper:
var _math = _interopRequireDefault(require('./math'));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
console.log(_math.default(5));

Other packages similar to @babel/plugin-transform-modules-commonjs

Changelog

Source

v7.23.3 (2023-11-09)

:bug: Bug Fix
  • babel-plugin-transform-typescript
    • #16071 Strip type-only TS namespaces (@colinaaa)
  • babel-generator
  • babel-compat-data, babel-plugin-bugfix-v8-static-class-fields-redefine-readonly, babel-preset-env
  • babel-plugin-transform-object-super
  • babel-helper-module-transforms, babel-plugin-transform-modules-amd, babel-plugin-transform-modules-commonjs, babel-plugin-transform-modules-umd
:memo: Documentation
  • #16044 docs: Update links in @babel/eslint-parser README (@aryehb)
:house: Internal
  • babel-core, babel-preset-env
:running_woman: Performance
:microscope: Output optimization
  • babel-plugin-transform-computed-properties

Readme

Source

@babel/plugin-transform-modules-commonjs

This plugin transforms ES2015 modules to CommonJS

See our website @babel/plugin-transform-modules-commonjs for more information.

Install

Using npm:

npm install --save-dev @babel/plugin-transform-modules-commonjs

or using yarn:

yarn add @babel/plugin-transform-modules-commonjs --dev

Keywords

FAQs

Last updated on 09 Nov 2023

Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install
SocketSocket SOC 2 Logo

Product

  • Package Issues
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc