-
Notifications
You must be signed in to change notification settings - Fork 12.8k
importing own package from test fails with error TS5055: Cannot write file #54299
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
Absent a more concrete argument about what is supposed to happen differently during which step of module resolution, this sounds like a misconfiguration |
@RyanCavanaugh the problem is that conventional node setup can not be configured. If there is a way to do it please let me know and I'm even happy to contribute doc improvements so it is covered. In short I do not believe there is a way to import modules by package name inside the package itself, while also providing typedefs to package users. That is because:
Concrete expectation is that typescript will be able to recognize that module is imported from the package itself and will not therefor attempt to compile own typedefs over. Even better if it will be smart enough to resolve actual source as opposed to typedef. |
Also I might be missing something but why would TS even try to compile any |
Only workaround I was able to find is to add a In the linked example it looks as follows "paths": {
"@web3-storage/data-segment": ["./src/lib.js"]
} It is not ideal, but at least it works |
Minimal repro: https://github.com/andrewbranch/js-self-name-import This looks like #47925 is just not quite doing its job for a JS project with |
Bug Report
I had been running into #14538 and turns out it is caused by the fact that my test files import the package by it's name (as opposed to relative path). Which as far as I can tell causes TS to look into
exports
of thepackage.json
which in my case looks likeWhich in turn confuses compiler into trying to compile
dist/src/lib.d.ts
file even thoughdist
is listed underexclude
of thetsconfig.json
.Here is the CI flow that was failing illustrating the problem. and exact git revision
Changing import in the test to use relative impart path fixes the problem, however that is an unfortunate limitation.
🔎 Search Terms
🕗 Version & Regression Information
This is a first time I'm able to try
"moduleResolution": "nodenext"
and is the issue I'm encountering.💻 Code
https://github.com/web3-storage/data-segment/tree/047ea5120de095ff60a4df00698b4736fcaf2cc5
🙁 Actual behavior
As you can see in CI flow output
🙂 Expected behavior
tsc --bulid
should pass without any errors.The text was updated successfully, but these errors were encountered: