I have a typescript project that uses commonjs modules, I use ts-node
to run it, and tsconfig-paths
to resolve tsconfig.compilerOptions.paths
at runtime.
now I want my project to migrate to use es modules, so I made some changes:
- add
type: module
to package.json - change
module: commonjs
toES2022
in tsconfig.json - change the command
ts-node
intonode --loader ts-node/esm
now all things are working perfectly, but it seems that tsconfig-paths
doesn't work in esm.
minimal reproductions:
es module project that is forked from the commonjs one, but modified to use es modules
in both projects:
- run
npm run build
to test compiling with typescript with esm - run
npm start
to testts-node
- run
npm start:paths
to testts-node
withtsconfig-paths