Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initializing ES6 module project with npm

Is there a way to have npm init directly set up an ES6 module, setting "type":"module" in package.json (or another npm command to set it)?

I always just modify package.json manually and add it, but I'm wondering if there's a way to do it directly with npm on the command line so I don't have to keep doing that. Just a convenience thing. Plus if I can do it with npm it's easier to automate.

like image 626
Jason C Avatar asked Oct 24 '25 16:10

Jason C


1 Answers

npm init itself doesn’t have a flag to auto-set "type": "module" in package.json. By default, it creates CommonJS projects.

So, there’s no direct npm init flag for "type": "module". The simplest automated way is:

npm init -y && npm pkg set type=module

like image 76
Abhishek Mishra Avatar answered Oct 26 '25 06:10

Abhishek Mishra



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!