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)?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With