📜 ⬆️ ⬇️

ECMAScript Modules in Node.js: New Plan

The current support status of ECMAScript modules (ESM) in Node.js:



In October, the Modules Team published a "Plan for the Implementation of New Modules . " This post explains what it contains.


Phases


The process is divided into three phases:



The minimum core will be the basis for future work. The new design will also replace the current experimental implementation as soon as it acquires similar capabilities.


Phase 1: Minimum ESM Support Core in Node.js


Simplify Module Ids


One of the goals of the Modules Team is to achieve "browser equivalence" : Node.js should be as close to the browser behavior as possible. The kernel achieves this by simplifying the parsing of module identifiers (URLs pointing to modules):



Bringing important CommonJS features to ES modules



Compatibility



 import {createRequireFromPath as createRequire} from 'module'; import {fileURLToPath as fromPath} from 'url'; const require = createRequire(fromPath(import.meta.url)); const cjsModule = require('./cjs-module.js'); 


Phase 2 and Future Plans



When can I use ES modules in Node.js?



Frequently asked Questions



Thanks


Thanks to Miles Borins for his feedback on this post.


Additional sources for further reading



')

Source: https://habr.com/ru/post/433964/


All Articles