vuejs / language-tools

⚡ High-performance Vue language tooling based-on Volar.js
https://marketplace.visualstudio.com/items?itemName=Vue.volar
MIT License
5.87k stars 405 forks source link

error TS2688: Cannot find type definition file for '.vue-global-types/vue_3.5_false.d.ts' #4860

Closed spacedawwwg closed 1 month ago

spacedawwwg commented 2 months ago

Vue - Official extension or vue-tsc version

2.1.6

VSCode version

1.93.1

Vue version

3.5.6

TypeScript version

5.3.3

System Info

System:
    OS: macOS 15.0
    CPU: (10) arm64 Apple M1 Max
    Memory: 6.98 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.15.1 - /usr/local/bin/node
    npm: 10.7.0 - /usr/local/bin/npm
    pnpm: 9.10.0 - /usr/local/bin/pnpm
    bun: 1.0.13 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 114.1.52.122
    Chrome: 128.0.6613.138
    Safari: 18.0

package.json dependencies

No response

Steps to reproduce

We're using a PNPM monorepo, each package has it's own type check. We run the these using Turborepo. The issue still happens randomly even type checking individual packages.

We're also using typescript references.

What is expected?

.vue-global-types/vue_3.5_false.d.ts is found

What is actually happening?

.vue-global-types/vue_3.5_false.d.ts is not found

Link to minimal reproduction

No response

Any additional comments?

We've tried adding

"plugins": [{ "name": "@vue/typescript-plugin" }],

directly to the tsconfig's and also tried adding

"paths": {
  "vue/__globalTypes_3.5_false": ["node_modules/vue/__globalTypes_3.5_false.d.ts"]
},

This didn't seem to help

KazariEX commented 2 months ago

.vue-global-types/vue_3.5_false.d.ts should exist directly in node_modules.

Logima commented 2 months ago

I have a similar problem, which might be related. In a PNPM monorepo I have one library and an app. The app includes some library files using relative paths, like ../../library/src/somefile.vue.

.vue-global-types/vue_3.5_false.d.ts is created inside app/node_modules, but not for the library or the repo root, which causes this error for files imported from library. I've previously used vue-tsc 1.8.27, which worked fine with this setup.

I tried to fiddle with vite-plugin-checker's vueTsc root/tsconfigPath options, but couldn't get the file to be generated to repo root node_modules.

trydofor commented 2 months ago

pnpm + monorepo, vue-tsc check UnoIcon.vue Error at .pnpm/@unocss

 ERROR(vue-tsc)  Cannot find type definition file for '.vue-global-types/vue_3.5_false.d.ts'.
 FILE  /Volumes/...../node_modules/.pnpm/@unocss+nuxt@0.62.4_magicast@0.3.5_postcss@8.4.47_rollup@4.22.0_webpack-sources@3.2.3_webpack@5.94.0_esbuild@0.23.1_/node_modules/@unocss/nuxt/runtime/UnoIcon.vue:4:23

    2 |   <div />
    3 | </template>
  > 4 | /// <reference types=".vue-global-types/vue_3.5_false.d.ts" />
Alex-D commented 2 months ago

My workaround was to not point on the other package via relative path but via node modules mananged by pnpm.

So I've replaced: ../../packages/my-package by node_modules/@company/my-package

in my TypeScript alias

trydofor commented 2 months ago

in my case, i downgrade the pnpm as follows, but i am not sure if it is all pnpm reson,

and, when using workspace:* protocol, e.g. monorepo front deps on "common":"workspace:*",

sometimes, in front project, regenerate .nuxt will no error :P

rm -rf .nuxt
pnpm dev
depressedX commented 1 month ago

same problem in pnpm monorepo.

Error happens when trying import .vue file in another package.

For example, when executing vue-tsc in /apps/my-app, it will generate .vue-global-types/vue_3.4_false.d.ts in /apps/my-app/node_modules.

Then we import my-lib/src/some-comp.vue which locates in /lib/my-lib, it cannot find a vue_3.4_false.d.ts for some-comp.vue since they are in different folders.

/apps
  /node_modules
    /.vue-global-types
  main.ts
/my-lib
  /node_modules
    [missing .vue-global-types]
  /src
    some-comp.vue
depressedX commented 1 month ago

https://github.com/vuejs/language-tools/blob/6916e42fb7109d9510e181de24f1a0f3d56da63b/packages/language-core/lib/utils/ts.ts#L289-L300

viewed source code, seems like it'll put .vue-global-types/vue_3.4_false.d.ts on the same level of vue in node_modules. But it's not guaranteed this file will be resolved by all triple slash of files from anywhere:

yield `/// <reference types=".vue-global-types/${options.vueCompilerOptions.lib}_${options.vueCompilerOptions.target}_${options.vueCompilerOptions.strictTemplates}.d.ts" />${newLine}`;

Anyone got any idea to fix this?

hubertmalkowski commented 1 month ago

Is there any workaround before the PR is merged? (btw nice work @depressedX!!!)

depressedX commented 1 month ago

Is there any workaround before the PR is merged? (btw nice work @depressedX!!!)

You use use pnpm-patch (or other third party library patch tool) to add changes in this PR to your project. And that's exactly how I did in my project.