@putout/plugin-convert-commonjs-to-esm
putout plugin adds ability to convert commonjs to ecma script module
Last updated 4 years ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @putout/plugin-convert-commonjs-to-esm 
SYNC missed versions from official npm registry.

@putout/plugin-convert-commonjs-to-esm NPM version

CommonJS is a module system supported in Node, it provides a require function, which can be used to access the exports object exposed by another file.

EcmaScript module syntax is the standard way to import and export values between files in JavaScript. The import statement can be used to reference a value exposed by the export statement in another file.

(c) parceljs

🐊Putout plugin adds ability to convert CommonJS to ESM. Use @putout/plugin-nodejs instead.

Install

npm i @putout/plugin-convert-commonjs-to-esm -D

Rule

{
    "rules": {
        "convert-commonjs-to-esm/require": "on",
        "convert-commonjs-to-esm/exports": "on",
        "convert-commonjs-to-esm/commons": "on"
    }
}

require

❌ Example of incorrect code

const {join} = require('path');

const args = require('minimist')({
    string: ['a', 'b'],
});

✅ Example of correct code

import {join} from 'path';
import minimist from 'minimist';

const args = minimist({
    string: ['a', 'b'],
});

exports

❌ Example of incorrect code

module.exports = () => {};

✅ Example of correct code

export default () => {};

Commons

❌ Example of incorrect code

const {readFile} = require('fs/promises');

await readFile(__filename);

✅ Example of correct code

import {readFile} from 'fs/promises';
import {fileURLToPath} from 'url';

const __filename = fileURLToPath(import.meta.url);
await readFile(__filename);

License

MIT

Current Tags

  • 10.0.1                                ...           latest (a year ago)

45 Versions

  • 10.0.1                                ...           a year ago
  • 10.0.0                                ...           a year ago
  • 9.2.0                                ...           2 years ago
  • 9.1.0                                ...           2 years ago
  • 9.0.0                                ...           3 years ago
  • 8.0.0                                ...           3 years ago
  • 7.1.1                                ...           3 years ago
  • 7.1.0                                ...           3 years ago
  • 7.0.0                                ...           3 years ago
  • 6.1.0                                ...           3 years ago
  • 6.0.0                                ...           3 years ago
  • 5.8.0                                ...           3 years ago
  • 5.7.0                                ...           3 years ago
  • 5.6.0                                ...           3 years ago
  • 5.5.0                                ...           3 years ago
  • 5.4.0                                ...           3 years ago
  • 5.3.0                                ...           4 years ago
  • 5.2.0                                ...           4 years ago
  • 5.1.0                                ...           4 years ago
  • 5.0.1                                ...           4 years ago
  • 5.0.0                                ...           4 years ago
  • 4.8.1                                ...           4 years ago
  • 4.8.0                                ...           4 years ago
  • 4.7.0                                ...           4 years ago
  • 4.6.0                                ...           4 years ago
  • 4.5.0                                ...           4 years ago
  • 4.4.0                                ...           4 years ago
  • 4.3.1                                ...           4 years ago
  • 4.3.0                                ...           4 years ago
  • 4.2.0                                ...           4 years ago
  • 4.1.0                                ...           4 years ago
  • 4.0.0                                ...           5 years ago
  • 3.0.0                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 1.7.0                                ...           5 years ago
  • 1.6.0                                ...           5 years ago
  • 1.5.1                                ...           5 years ago
  • 1.5.0                                ...           5 years ago
  • 1.4.1                                ...           5 years ago
  • 1.4.0                                ...           5 years ago
  • 1.3.0                                ...           5 years ago
  • 1.2.1                                ...           5 years ago
  • 1.2.0                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (10)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE