-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
ts error when moduleResolution is "node16" #104
Comments
I see you closed this, is there a resolution for this? |
The same problem occurs when I use other plugins. I closed this issue because I'm not sure if this is my project configuration problem. Now I temporarily use I noticed that if there is a named export, this problem can be circumvented //@vitejs/plugin-react/dist/index.d.ts
// export { BabelOptions, Options, ReactBabelOptions, viteReact as default };
export { BabelOptions, Options, ReactBabelOptions, viteReact, viteReact as default }; // import reactPlugin from '@vitejs/plugin-react';
import {viteReact} from '@vitejs/plugin-react'; It seems that I should keep this issue open |
Hi, |
Same error for me running vite+react on Deno 1.13.3 with TS 4.9. |
I had a similar issue and I believe Quick summary: In I'd be happy to roll a PR to add a |
More details of the broken types for
|
For me what fixed it was creating a patch using
See example commit here: karlhorky/archive-webpage-browser-extension@ad3a5e6 |
Hi! With the team we decided to not invest more time in the node16 resolutions issues. This IMO a bad design and this as been fixed with TS 5 bundler mode that more clearly represent how most apps and projects are built. |
Just to voice the sentiment that will be certainly coming also from others: this is an unfortunate decision by your team, and is also a bit user-hostile, for those users who need to use some module resolution format for some reason. Probably the changes to the packages amount to changes to a handful of lines of code, and then you will have proper, non-broken interop with TypeScript 4.7+. Otherwise you are putting this burden on all of your consumers - either to maintain patches for your broken types or to somehow special-case their environments for Vite plugins. I would strongly suggest bringing this back to the team and reconsidering this decision. |
What is the motivation for using node16 instead of bundler? |
@ArnaudBarre Thanks for the message — I understand if supporting all module resolutions isn’t as important as other features, especially if TS 5 also solves the problem. For motivation — I would like my runtime and TS check to use the same module resolution rules, to align on one way of managing modules and file names. This reduces the number of concepts people need to understand when working on and maintaining the project. I spent some time debugging why my TS build was failing with nodenext and node16. What do you think about adding a note in the readme that these module resolution types are not supported, to help others understand that the issue is not something in their local code? You mentioned “if you’re not able to migrate…”. Is there an upgrade path to TS 5 with Vite currently? |
This is exactly why the TS team added the bundler resolution, so that TS resolutions is more close (and maybe totally identical when using pure esm with explicit extensions) to how bundler like Vite resolve modules. So yeah you can now update TS to v5, and then update your TS config to use this new resolution, opt-in to Here is my config:
I will add a note in the readme to advice using this resolution algorithm. |
Thank you! Fantastic support @ArnaudBarre, appreciate it. |
There are other reasons to support From what I remember why we chose But I'm not the best one to talk about the benefits here - I'm sure there is more that I'm leaving out. I'm just mentioning that Vite and related packages should try to be interoperable with the module systems and ecosystem. It should not have errors on Are the types wrong?. To be against interop like this makes me lose confidence in the robustness and maintenance of Vite and its ecosystem. |
For the ambiguity and performance point, bundler mode + allowImportingTsExtensions is way better. Vite goal is to help the ecosystem use ESM tools. We also don't support tools or libraries that do crazy things with cjs requires that webpack is able to support. |
👋 Hello from the TS team. There seems to be some confusion here about when it’s appropriate to use different Libraries have been explicitly discouraged from relying on
The configuration published now is incorrect, full stop. Any library that can be successfully imported by modern versions of Node must be compatible with
It’s understandable and correct to be annoyed by trying to use 1 The answer is somewhat complicated by the fact that Vite instruments Node with a custom ESM loader that makes module resolution more forgiving—I’m guessing |
As your note shows, the reality is a lot more complex than "the user config is running in node". Most of people will use a TS config nowadays, and this file is clearly bundled and transformed before being executed. From what I remember (and what annoys me, correct me if I'm wrong), the node16 resolution forces you to import |
|
That good news, I missed that
Yep clearly something that would be needed once node loaders become stable. The fact TS imports are not ban will really make this simple to write.
This true but not clearly not an expected usage.
Removing entries from the export map feels like going backward. Would this not break bundler resolution ? |
Every TypeScript resolution mode supports extension matching to sibling files. If every If the types are not colocated with the implementation, or you just want to be explicit in the export map, you can use nested conditions:
Just note that this does not make it possible to reuse a single
is equivalent to what is published today. In other words, just because you reach a file via the |
Describe the bug
I am migrating my node application from cjs to mjs. When I set
"moduleResolution": "node16"
intsconfig.json
, thevite.config.ts
reportsThis expression is not callable. Type 'typeof import("/node_modules/@vitejs/plugin-react/dist/index")' has no call signatures.ts(2349)
.I tried to change
reactPlugin()
toreactPlugin.default()
, the error disappears but vite build failed with errorTypeError: reactPlugin.default is not a function
Reproduction
https://stackblitz.com/edit/vitejs-vite-4x7wea?file=tsconfig.json,vite.config.ts,tsconfig.node.json&terminal=dev
Steps to reproduce
set compilerOptions.moduleResolution = 'node16' in tsconfig.json
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: