-
Notifications
You must be signed in to change notification settings - Fork 143
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
TypeScript cannot find declaration files with module nodenext #960
Comments
Interesting, I wonder how's it working for other projects right now 🤔 |
Here's a reproduction:
Opening Here's also a Codesandbox reproduction: I've tried installing other projects that ship with types and types for those get detected correctly. VSCode only shows this problem with Blade. Here's a side-by-side comparison. TypeScript is able to find types for a library that ships with a It looks like this bug occurs only when the project is using But as shown in the above screenshot, TypeScript can figure out types when defined explicitly so relying on automatic detection is not a reliable long-term solution. Related: microsoft/TypeScript#50058 (comment) |
can you check once and post what version of TS server is set on your vscode? |
can you switch to 4.9? because we had added module-specific resolution for |
@cseas I noticed you didn't specify If you set |
No, moduleResolution takes the same value as module when module is set to Changing the More on this: How can I make my TypeScript project output ESM? Also, as pointed out in this comment, TypeScript finds declaration files correctly for other UI libraries. So the problem isn't the setup/config here, the issue is that Blade is not supporting a setup that wants to bundle as ESM. |
Okay I see, you want a pure ESM output, then in that case we can check if types field resolves the issue, but we need to see if it can work with moduleSuffixes since it needs to work seamlessly across RN and web. |
Yes, the RN support is what I'm not sure about. The solution I suggested in the issue description will solve it for web projects but that could possibly break the types for RN. As an alternate solution, maybe if we just rename
Update: ^ Just tried this fix manually. It works for |
@cseas from the codesandbox repo you sent above I see things are working fine 🤔 |
My bad. I was playing around with the tsconfig values to debug another issue. Didn't realise Codesandbox saved it. Try now, the issue should come up. Here's the tsconfig that reproduces the issue: {
"compilerOptions": {
"jsx": "react-jsx",
"module": "NodeNext"
}
} |
Another question: to make this work as per your doc link |
That's correct, ESM version of libs should either ship with the My assumption is that there's no issues because the The GitHub repro I linked above has Related discussion: microsoft/TypeScript#18442 (comment) |
Problem
Blade ships with
d.ts
declaration files. However, since the bundledpackage.json
doesn't contain a"types"
field, the consumer project is unable to find these declaration files and as a result ignores the types for components that Blade ships.VSCode can't find the declaration files either as shown by the below warning:
This means that IntelliSense in the editor doesn't work for types/props. Also, passing wrong props to a component works. For example, the below component compiles without errors.
Solution
The
package.json
should contain a "types" field that points to the declaration file so the bundler and IDE can find it.Refer ESM guide for types in
exports
field: https://www.typescriptlang.org/docs/handbook/esm-node.htmlNote that the fallback types field in the above link is required even for ESM bundles right now because proper support for
exports
field is a part of TypeScript 5 milestone: microsoft/TypeScript#50794 (comment)The text was updated successfully, but these errors were encountered: