Skip to content
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

During type checking, the type files in vitest and vite cannot find the type they use #4921

Closed
6 tasks done
yingpengsha opened this issue Jan 10, 2024 · 3 comments
Closed
6 tasks done

Comments

@yingpengsha
Copy link
Contributor

Describe the bug

My type checking use case passed without a hitch, but there was a problem with the type inside the library itself

⎯⎯⎯⎯⎯⎯ Typecheck Error ⎯⎯⎯⎯⎯⎯⎯
Error: Error: node_modules/.pnpm/@[email protected]/node_modules/@vitest/utils/dist/error.d.ts(4,58): error TS2304: Cannot find name 'WeakKey'.
Error: node_modules/.pnpm/@[email protected]/node_modules/@vitest/utils/dist/error.d.ts(6,96): error TS2304: Cannot find name 'WeakKey'.
Error: node_modules/.pnpm/@[email protected]/node_modules/@vitest/utils/dist/error.d.ts(6,133): error TS2304: Cannot find name 'WeakKey'.
Error: node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/index.d.ts(6,41): error TS2307: Cannot find module 'rollup/parseAst' or its corresponding type declarations

Reproduction

System Info

> This is my local environment configuration, of course, can also reproduce the previous problem

  System:
    OS: macOS 13.4
    CPU: (12) arm64 Apple M2 Pro
    Memory: 122.00 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.20.1 - ~/.nvm/versions/node/v16.20.1/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.20.1/bin/yarn
    npm: 8.19.4 - ~/.nvm/versions/node/v16.20.1/bin/npm
    pnpm: 7.33.6 - ~/.nvm/versions/node/v16.20.1/bin/pnpm
    bun: 1.0.0 - ~/.bun/bin/bun
  Browsers:
    Chrome: 120.0.6099.199
    Edge: 120.0.2210.121
    Safari: 16.5

Used Package Manager

pnpm

Validations

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Jan 12, 2024

The issue might be related to

Probably your tsconfig is somewhat old-ish compared to what Vite/Vitest expect and having "moduleResolution": "Bundler" and "lib": ["ESNext"] might be recommended, something like:

{
"compilerOptions": {
"target": "ESNext",
"lib": ["esnext"],
"module": "ESNext",
"moduleResolution": "Bundler",

Or disabling type check inside dependencies would probably workaround this and somewhat common thing to do as well:

"skipLibCheck": true

For some reason, I cannot run your repo locally (somehow Vitest is stuck) so I couldn't verify though. It might be nice if you can minimize repro further.

@mrazauskas
Copy link

mrazauskas commented Jan 12, 2024

Upgrading TypeScript and running tsc --noEmit in the reproduction repo, gives: "Cannot find module 'rollup/parseAst' or its corresponding type declarations." This looks like #4567. Following the thread one can find a workaround in rollup/rollup#5199. As already mentioned, the suggestion is to use moduleResolution: "bundler". I just wanted to make it clear what is the reason here.

moduleResolution: "bundler" make tsc --noEmit work on TypeScript 5.2.

Running tsc --noEmit with TypeScript 5.0 and 5.1 complains that it "Cannot find name 'WeakKey'" in several places of @vitest/utils. It is not easy to browse through TypeScript's repo, but seems like the WeakKey type was add in microsoft/TypeScript#54195. If I get it right, the WeakKey type shipped with TypeScript 5.2-beta.

Does it mean vitest --typecheck supports only TypeScript 5.2 and up? And/or requires moduleResolution: "bundler"? (By the way, with these changes and also "skipLibCheck": true added, it still gets stuck for me in the reproduction repo.)

Should these details be added to Vitests documentation, perhaps?

@yingpengsha
Copy link
Contributor Author

yingpengsha commented Jan 12, 2024

@hi-ogawa I'd like to express my deep appreciation for the solution you provided. It was very detailed and helped me successfully resolve this problem.

As for the issue you mentioned about not being able to reproduce the problem on your end, it might be because I updated the code afterwards. If you wish to reproduce it, I have created a separate branch with the original code at repord/vitest-type-issue .

However, I have encountered a new issue, which you also noticed in my latest code. It seems that Vitest is getting stuck during execution. I will create a separate reproduction to confirm this issue and will open another issue for discussion once it's consistently reproducible.

Also, I believe the suggestion made by @mrazauskas is valuable. I think the results of the testing phase should be as close as possible to the state during development. It's always puzzling when unexpected issues arise during testing that weren't anticipated during development.

I'll close this issue and open it again if there are further discussions.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants