Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Node.js –experimental-vm-modules command line option vs "type": "module" in package.json

I’m currently rewriting a NodeJS project from a messy combination of CommonJS and Babel-transpiled ES Modules to be completely ES Module based.

In the process, I’ve become a bit confused by how Node handles these things. I’ve tried to read up on it, but I seem to be missing one final piece in my understanding.

I was assuming I would no longer need to use Babel to transpile the ES Modules. This seems to be correct. However, when I run my (Jest) tests, I still need to use the –experimental-vm-modules Node flag to make everything work.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My question is: what does that flag do? Reading the documentation, this seems to enable ES Modules, but didn’t I already enable ES Modules by specifying "type": "module" in the package.json file?

Relevant links:

>Solution :

Specifying type: "module" in package.json just telling library authors your source code is based on ESM.

For jest, you need to use experimental-vm-modules because the node api jest uses to enable ESM support is still not stable as of node 18.x

https://jestjs.io/docs/ecmascript-modules

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading