using tsconfig-paths with es modules
Asked Answered
F

0

6

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 to ES2022 in tsconfig.json
  • change the command ts-node into node --loader ts-node/esm

now all things are working perfectly, but it seems that tsconfig-paths doesn't work in esm.

minimal reproductions:

in both projects:

  • run npm run build to test compiling with typescript with esm
  • run npm start to test ts-node
  • run npm start:paths to test ts-node with tsconfig-paths
Fervency answered 17/1, 2022 at 12:58 Comment(1)
The Node.js runtime analog of TypeScript's path mapping is subpath imports.Interested

© 2022 - 2024 — McMap. All rights reserved.