You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
--module nodenext self-name references don't work with an outDir from clean build #46762
Hello, your beta announcements are asking for feedback on this feature. First of all - I'm super excited about this! Great work!
One thing I was really looking forward to in Node.js exports/ESM support was having example files that import from the library itself - this way we can just say import { foo } from "my-module" rather than import { foo } from ".." /* TODO: replace this with "my-module" */ - makes it much easier for users to copy/paste examples whilst keeping the examples co-located inside the package.
Node.js supports this "self-referencing" behaviour; however TypeScript doesn't seem to understand how to import this in module:"nodenext" mode - a could not find a declaration file for module 'my-module' error is raised.
I've prepared a minimal reproduction here with js folder working using Node.js and analogous ts folder which is not working with TypeScript (won't compile):
The self-name reference works but resolves to ./dist/index.d.ts, which means it’s always going to be one build stale, and a clean build will not be able to resolve anything.
Don’t know if this was discussed but this almost feels like project reference to ourself with using source files instead of .d.ts files and mimicking that they are present for module resolution like we do through tsserver .. may be a solution could be to use that for own tsconfig ?
Activity
andrewbranch commentedon Nov 10, 2021
The package.json here is
{ "name": "@localrepo/ts", "type": "module", "exports": { ".": "./dist/index.js" }, "dependencies": { "@types/node": "^16.11.7", "typescript": "^4.6.0-dev.20211110" } }The self-name reference works but resolves to
./dist/index.d.ts, which means it’s always going to be one build stale, and a clean build will not be able to resolve anything.Offirmo commentedon Apr 28, 2022
Hi, this is definitely a problem for enabling module self-reference as advertised in TypeScript 4.5, cf. this situation: #38675 (comment)
Thanks for the fix and hopefully we'll get it soon!
sheetalkamat commentedon Apr 29, 2022
Don’t know if this was discussed but this almost feels like project reference to ourself with using source files instead of .d.ts files and mimicking that they are present for module resolution like we do through tsserver .. may be a solution could be to use that for own tsconfig ?
weswigham commentedon Apr 29, 2022
Maybe as a workaround, but that's a bit far from first-class support for what is now a core node resolution feature.
Offirmo commentedon May 6, 2022
Thanks a lot Wesley Wigham (@weswigham) I can't wait to try it!
benjie commentedon May 20, 2022
Thanks for this Wesley Wigham (@weswigham) 🙌 ❤️
The fix/feature is out in
typescript@rc(4.7.1-rc) and seems to be working well so far 🚀