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)?
Advertisement
Answer
Using TS Module
Install globally:
JavaScript
x
2
1
yarn global add @tsmodule/tsmodule
2
Create a new project:
JavaScript
1
2
1
tsmodule create [—-react] project-name
2
Or convert your project to a TS Module (ESM + TypeScript):
JavaScript
1
2
1
tsmodule convert
2
See https://github.com/tsmodule/tsmodule.
Using create-esnext
Install create-esnext
globally:
JavaScript
1
6
1
yarn global add create-esnext
2
3
# or
4
5
npm i -g create-esnext
6
In the folder where you would run npm init
:
JavaScript
1
6
1
yarn create esnext
2
3
# or
4
5
npm init esnext
6