Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to "npm init" an ES module?

All modern versions of Node need to run packages as modules is "type": "module" in package.json, but I don't see any flags for npm init or yarn init that will add that property.

Is there a flag for either package manager or an easy way to add the value to package.json (i.e., npm package-property set type module or something similar)?

like image 419
C. Lewis Avatar asked Nov 21 '25 07:11

C. Lewis


2 Answers

Saw this question a while ago, and for the longest time I used "npm init esnext". I just figured out how to edit package.json keys directly from the command line:

npm init -y; npm pkg set type="module";

Although the first command will log the content of package.json without "type": "module" to the console, if you open package.json you will see that it has been added properly by the second command.

like image 178
stackoverflow221 Avatar answered Nov 23 '25 20:11

stackoverflow221


This does exactly what you asked:

npm init es6

It creates a package.json with the "type": "module" setting.

source: https://www.npmjs.com/package/create-es6

like image 29
Arthur Avatar answered Nov 23 '25 20:11

Arthur



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!