-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Unresolved TypeScript definition paths (when using node-esm with imports
)
#48639
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
|
Is it possible to warn a user when resolution fails under |
@weswigham thoughts? |
If resolution outright fails, yeah, we should be able to. Most package authors have a |
Hey! So if my
import { AuthMessageType, LoginRequestMessage, LoginSuccessMessage, LoginFailureMessage, } from '#src/messaging/auth';
import { AuthMessageType, LoginRequestMessage, LoginSuccessMessage, LoginFailureMessage } from '#src/messaging/auth'; Another module importing this library shows all imported types as I still don't know what the best solution might be, but my brain keeps falling back to the idea of another {
"compilerOptions": {
"paths": {
"#src/*": [
"./src/*.ts"
]
},
"typeDefPaths": {
"#src/*": [
"./dist-types/*.d.ts"
]
}
}
} -but I don't know how philosophically compatible or elegant this solution would be. EDIT: Admittedly, I feel like I'm using the whole system improperly right now. I just wanted a nice, clean method for absolutely referencing sources files from deep within internal modules (at mostly like -- a couple files). It won't be a big deal to switch to relative-only imports (I already have on another branch), but I'm just curious to know what the intended solution be for a situation where the TypeScript definitions and source files need their import paths to be resolved differently. What would TypeScript do? |
I appreciate you stress testing these features! My personal recommendation would be to not split out your |
@schmannie You just need #47925 - your non-relative imports point to the output location for your project (correctly), but TS currently isn't smart enough to remap those output files back to the program's input files for nonrelative imports (the workaround being, ofc, to use relative imports for input files for the time being - it's actually a very very longstanding bug that's only becoming critical now that import maps exist at runtime). |
I understand. Thank you very much! I've just opted to switch to relative imports as @weswigham suggested. Looking forward to seeing how #47925 pans out! Let me know if I should do anything to this issue in the meanwhile. |
Tracking as duplicate of #46762. Thanks! |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Hey there!
Bug Report
I'm writing a small, shared module to be imported in other TypeScript programs and I noticed a slight error with my generated TypeScript definitions (that might not be a bug, yet I'm unsure of how to fix).
I wanted to be able to reference my
src
folder in my project root as#src
, so I added the requiredimports
andpaths
in mypackage.json
andtsconfig.json
respectively.After letting
tsc
generate my JavaScript, I'm able to run the project just fine -- however, importing my library in another TS project showed me that the TypeScript definitions were also using the Node.js-like#src
path, but were obviously not resolving properly and couldn't be loaded.What would be my best course of action to fix this? I understand that this type of module resolution is just something Node.js's doing (based off of
packge.json/imports
), so what would TypeScript's solution be to projects using this feature? Can I use custom, local imports in mypackage.json
yet resolve emitted type definitions correctly?🔎 Search Terms
package.json esm imports type declarations emitted path incorrect resolve
🕗 Version & Regression Information
imports
, generates types that are consumed anywhere[email protected]
nightly build💻 Code
Here are the relevant bits from my
package.json
file:...and
tsconfig.json
file:🙁 Actual behavior
The resulting type declarations,
./dist-types/index.d.ts
in my project for example, has imports such as:...and while generated JS in
./dist-esm
resolves#src
just fine, TypeScript has no idea where to find the rest of my type definitions.🙂 Expected behavior
I'm not sure to be honest. The TypeScript config's
paths
definition is technically working just fine, as my source files are mapped correctly -- what would the equivalent, or generally correct way of fixing this for just the type definitions be?The text was updated successfully, but these errors were encountered: