dividab / tsconfig-paths

Load node modules according to tsconfig paths, in run-time or via API.
MIT License
1.8k stars 100 forks source link

Native ESM support with ts-node on NodeJS with .mts files #221

Open andriichern opened 2 years ago

andriichern commented 2 years ago

Could not find any config that would be suitable for ts-node usage that supports esm modules. Would appreciate any links on how to set up tsconfig-paths together with --loader ts-node/esm option.

If no do you plan to support new .mts and .cjs file extensions?

einSelbst commented 2 years ago

if you don't care about the paths in particular you could follow the setup in this (not mine) example repo https://github.com/felipeplets/esm-examples

Have a look at the linked stackoverflow answer too. See my (currently) open PR regarding the need for a specific flag for node-ts to work with relative imports too.

andriichern commented 2 years ago

@einSelbst actually I tried to care about paths that were specified in paths property of tsconfig but now I can not. And this was the reason for this issue: run TS code with ts-node & tsconfig-paths (on VS Code also) that will then compiled to native esm modules and run on Node, not in browser)))

And the problem is that currently tsconfig-paths expects only .ts files and fails with .mts files (which are extensions for native Node .mjs files)

einSelbst commented 2 years ago

@andriichern there is also https://www.npmjs.com/package/@swc-node/core which seems to support paths but I haven't used it myself. Don't know anything about VSCode support or handling of mts files tough.

testgitdl commented 1 year ago

We also need a solution for this. Any idea when it will be available? Thank you!

slavafomin commented 1 year ago

I'm writing an ESM migration guide and have stumbled upon this problem too. Has anybody found a solution for this?