Skip to content

Import and Require ES Module #4929

Answered by smit-code
Axitvadi asked this question in Q&A
Discussion options

You must be logged in to vote

Since Node v12 (April 2019), support for ES modules is enabled by default, and since Node v15 (October 2020) it's stable (see here). Files including node modules must either end in .mjs or the nearest package.json file must contain "type": "module". The Node documentation has a ton more information, also about interop between CommonJS and ES modules.

Performance-wise there is always the chance that newer features are not as well optimized as existing features. However, since module files are only evaluated once, the performance aspect can probably be ignored. In the end, you have to run benchmarks to get a definite answer anyway.

ES modules can be loaded dynamically via the import() funct…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Axitvadi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants