-
-
Notifications
You must be signed in to change notification settings - Fork 540
Relative .js imports still not resolved to .ts (under Yarn PNP?) #2148
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
Comments
@earshinov I don't see this in your tsconfig. Have you tried this setting?
See https://typestrong.org/ts-node/docs/options#experimentalresolver |
@t1bb4r , Thank you for looking into this. Tried it right now -- doesn't seem to change anything. Also added it to GitHub actions: https://github.com/earshinov/repro-ts-node-esm-yarn-pnp/actions/runs/12697806025/job/35394904259. package.json: "scripts": {
"test-with-experimental-resolver": "TS_NODE_PROJECT=tsconfig.ts-node-experimental-resolver.json yarn node --loader=ts-node/esm.mjs --loader=./.pnp.loader.mjs -- src/main.ts",
} tsconfig.ts-node-experimental-resolver.json: {
"extends": "./tsconfig.json",
"ts-node": {
"experimentalResolver": true
}
} |
you need to remove |
@kbaba1001 , I want my script to be executed as an ESM module, that's the point |
Turned out I incorrectly invoked yarn: when running |
Search Terms
ts-node, esm, ts-node-esm, yarn-pnp
Expected Behavior
Given:
I shouldn't have problems running this TypeScript code with ts-node:
Command (actually a package.json script) being used:
Actual Behavior
Steps to reproduce the problem / Minimal reproduction
Repro project: https://github.com/earshinov/repro-ts-node-esm-yarn-pnp/
The error is seen in the GitHub actions workflow: https://github.com/earshinov/repro-ts-node-esm-yarn-pnp/actions/
Specifications
tsconfig.json:
package.json:
Workaround
Using a dump custom resolver. Command:
Custom resolver:
Output:
References
#1361 - most relevant piece of information I have found. Judging by the fact that the issue is closed and the relevant pull requests have been merged, it would seem that the problem has been fixed >1 year ago, except it apparently wasn't. Or maybe I'm dumb and there is another trap somewhere (as it usually is when it comes to Node.js, Yarn PNP, TypeScript and ESM).
✨Solution ✨
Do not pass
--loader=./.pnp.loader.mjs
when runningyarn node
, yarnpkg/berry#6645 (comment)The text was updated successfully, but these errors were encountered: