-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for ts-node + tsconfig-paths + esm #243
Comments
I started the relevant changes here: master...Danielku15:tsconfig-paths:feature/ts-node-esm The new I could prepare a full PR if there is a chance of getting it merged. Unit Tests are missing at this point. After integrating a test build into my own project (TypeScript Codebase+Mocha+ESM+ts-node+tsconfig-paths), I got it even running with the Test Explorer VS Code Extensions: |
@Danielku15 have you tried out tsx? |
@effervescentia |
Interesting... I use it on a project that runs a NestJS application and uses decorators heavily and haven'y had any issues |
@8naf I was able to get it working by adding an explicit |
Fantastic! Everything is working now. I had to struggle all day to find a way to solve this issue. |
tsx still doesn't look like it can run typeorm |
I'm actually using |
Is there a way to get ESM supported in |
Any updated? |
@Danielku15 any chance to use with ESM? The following does not work still: NODE_ENV=development node --experimental-specifier-resolution=node --loader ts-node/esm -r tsconfig-paths/register ./src/index.ts |
@damianobarbati I am currently moving over towards |
I am currently trying to migrate the browser based tests (Rollup+Karma+Jasmine) of my TypeScript project to a node based setup (ts-node+mocha) but unfortunately it seems almost every package lacks some features, especially around ESM.
ts-node
would have ESM support, but doesn't have paths supporttsconfig-paths
hasts-node
support but no ESM support.So I attempted to get tsconfig-paths running with ESM and was successful by hooking into the resolve process. But it is still a bit hacky currently because
ts-node
doesn't export the relevant modules, andtsconfg-paths
doesn't have a public API of resolving the actual file that was found to match a configuredpaths
. First some code:Usage via node
Usage via .mocharc.json
ts-node-esm-paths.mjs
What I've done:
ts-node/esm
. This makes the usage easier because only one single loader has to be specified everywhere. But ts-node doesn't export some internal files, so we are required torequire
them via absolute path.ts-node/esm
I override some internal functions of it (like the tsconfig-paths/register does it for the CJS file loading). I override theresolve
function used internally and there usetsconfig-paths
to map the specified to the real file.In tsconfig-paths we could ship this maybe with two steps as a new feature:
matchPath
needs an extension to get back the final file path of the module which was found.registerAndCreateEsmHooks
with a callback for resolving we can import in atsconfig-paths/esm
The text was updated successfully, but these errors were encountered: