Published on

Changing npm package.json "type" to "module" via CLI

Authors

Ever wondered how to instantly change your package.json's type configuration to "module" or "commonjs" instantly?

Well, with npm pkg command you can do it.

How to change it to "module" (ESM)

Just run the following

npm pkg set type="module"

Change it back to "commonjs"

Similarly run:

npm pkg set type="commonjs"

And that's pretty much it.

Happy changing config!