-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Compatibility issue between dts output method and yarn's strict dependency resolution approach #53580
Comments
If this issue cannot be resolved in both yarn and TypeScript, I would appreciate it if you could let me know how I can work around the problem. |
Given that C lists an import for A, a fix would be to declare that C depends on A so the import resolves. If the package is out of your control, you could use: https://yarnpkg.com/configuration/yarnrc#packageExtensions If you explicitly annotate the type, you may also be able to avoid this generated node. |
Thanks for your fast response! I needed a solution from the TypeScript side.
I might not have understood this correctly. If we explicitly provide A's type from B to C, will it resolve the issue?
And while reproducing the issue, I found out that this problem only occurs with interfaces, not with types. Is there any documentation that explains why types aren't imported using the import function? |
Probably, via the explicit annotation. |
The declaration emitter will always (if it can) use an explicit type annotation based on the one you wrote, so that solution is definitely available. If it can't do that, it has to synthesize some name for that type, and it's possible (indeed likely) that the only way to refer to the type is through an |
…which IIRC is caught by, e.g. |
AFAIK |
Hmm, then what's the deal with the error that goes something like "type T cannot be named without reference to module 'foo'" that only shows up when declarations are enabled? Am I misunderstanding the purpose of that error? |
That error appears when the specifier of the module appears non-portable, e.g. would be something like |
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow or the TypeScript Discord community. |
I think this problem maybe resolve by #58176 |
Potentially, do try the next nightly and report back! |
Bug Report
🔎 Search Terms
yarn, yarn berry, pnp, interface, dependency hoisting, module resolve
and... yarnpkg/berry#5287
🕗 Version & Regression Information
and typescript 5.0.0
I've been experiencing a compatibility issue between the output method of TypeScript's .dts files and yarn's strict dependency resolution approach, which has led to dependency problems in my project.
I would like to provide more details about this issue:
I'm in the following situation: I have 3 packages, A, B, and C, with dependencies in the order of A -> B -> C.
Package A exports the following code (this is part of the actual code):
Package B uses createThemedStyled from package A:
Finally, package C uses styled from package B:
After building each package and generating their dts, the output for package C's dts looks like this:
However, it seems that in pnp, if package C doesn't explicitly have package A as a dependency, A cannot be resolved. This works correctly with nodeLinker: node-modules.
And I don't think this issue is tied to a specific library or the TypeScript compiler.
This issue seems to occur only in the dts, and adding package A to the devDependencies of the problematic package C resolves the issue.
The log is part of result of
tsc --traceResolution
about C package.⏯ Playground Link
💻 Code
reproducing repo: https://github.com/flex-jonghyen/pnp-reproduce
🙁 Actual behavior
The problem is importing dependencies of dependencies in .dts files that are unknown to the consumer.
🙂 Expected behavior
The problem does not occur.
The text was updated successfully, but these errors were encountered: