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

Cannot find module *.vue or its corresponding type declarations when components live in hidden directories #3349

Closed
nekomeowww opened this issue Jul 2, 2023 · 9 comments · Fixed by #3450
Labels
duplicate This issue or pull request already exists good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first

Comments

@nekomeowww
Copy link

Summary

image

Encountered Cannot find module './C2.vue' or its corresponding type declarations. issue when opening a component that lives in a hidden directory (with . prefixed) in Visual Studio Code with Volar with the following behaviors:

  • vue-tsc --noEmit with no errors.
  • can navigate to the correct component when holding CMD and clicked the imported path in source code files.
  • the components lives in the non-hidden directories (without . prefixed) directories are fine, such as src, dot.
  • can be compiled, bundled successfully and working properly when in development, production modes, previews.

Such issue was initially appeared when I was developing some extension components for my VitePress site and the components was lived in .vitepress directory.

Reproduction

GitHub Reproduction Repo: https://github.com/nekomeowww/reproduction_volar_cannot_find_vue_module
Stackblitz Reproduction: https://stackblitz.com/github/nekomeowww/reproduction_volar_cannot_find_vue_module

Already done troubleshooting

  1. I almost checked every issues, webpages that appeared under GitHub, StackOverflow and Google with the term "Cannot find module" "vue" with no luck.
  2. Tried different content, filenames of shims.d.ts for declare module '*.vue' statement:
declare module '*.vue' {
  import type {DefineComponent} from 'vue'
  const component: DefineComponent<object, object, any>
  export default component
}
declare module "*.vue" {
  import Vue from 'vue';
  export default Vue;
}
  1. Tried configure more includes path for tsconfig.json with **/*.d.ts, **/*.vue with no luck.
  2. Tried to copy and paste the tsconfig.json from either antfu/vitesse and vuejs/vitepress with no luck.
  3. Tried to globally or workspace partially disable @builtin typescript JavaScript and TypeScript language feature extension within VSCode with no luck.
  4. Tried the latest Vue StackBlitz playground and default configuration with no luck.

Envs and Confs

Extensions

Visual Studio Code

Version: 1.79.2 (Universal)
Commit: 695af097c7bd098fbf017ce3ac85e09bbc5dda06
Date: 2023-06-14T08:58:52.392Z (2 wks ago)
Electron: 22.5.7
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Darwin arm64 22.5.0
Extensions
TypeScript Vue Plugin (Volar) v1.8.3
Vue Language Features (Volar) v1.8.3

Runtime and package manager

Node.js v18.16.1
Pnpm v7.0.0

Dependencies

package.json:

{
  "devDependencies": {
    "@vitejs/plugin-vue": "^4.2.3",
    "typescript": "^5.1.6",
    "vite": "^4.3.9",
    "vue": "^3.3.4",
    "vue-tsc": "^1.8.3"
  },
  "type": "module"
}

tsconfig.json:

{
  "compilerOptions": {
    "module": "ESNext",
    "target": "ESNext",
    "strict": false,
    "esModuleInterop": true,
    "jsx": "preserve",
    "skipLibCheck": true,
    "isolatedModules": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "noUnusedLocals": true,
    "strictNullChecks": true,
    "allowJs": true,
    "forceConsistentCasingInFileNames": true,
  },
  "exclude": [
    "**/node_modules/**",
    "**/dist/**",
  ]
}
@johnsoncodehk johnsoncodehk added pending triage good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first labels Jul 2, 2023
@nekomeowww
Copy link
Author

Any updates?

@sfe-efficy
Copy link

Same problem here jumping from 1.8.1 to 1.8.5 (I didn't check versions between them)

@rchl
Copy link
Collaborator

rchl commented Jul 19, 2023

This is a duplicate of #3328

As should be clear from the linked issue you can explicitly state which vue files to process by adding include to tsconfig.json:

  "include": [
    "./.dot/**/*.vue",
    "./dot/**/*.vue",
    "./src/**/*.vue",
  ]

or something more generic.

@sfe-efficy
Copy link

This is a duplicate of #3328

As should be clear from the linked issue you can explicitly state which vue files to process by adding include to tsconfig.json:

  "include": [
    "./.dot/**/*.vue",
    "./dot/**/*.vue",
    "./src/**/*.vue",
  ]

or something more generic.

It's true, I was having similar configuration, but for one folder in another place it was missing to include manually.
Thanks ;)

@so1ve
Copy link
Member

so1ve commented Jul 28, 2023

Duplicate of #3328

@so1ve so1ve marked this as a duplicate of #3328 Jul 28, 2023
@so1ve so1ve closed this as not planned Won't fix, can't repro, duplicate, stale Jul 28, 2023
@so1ve so1ve added duplicate This issue or pull request already exists and removed pending triage labels Jul 28, 2023
@so1ve
Copy link
Member

so1ve commented Jul 28, 2023

And should be fixed by #3450

@csh0101
Copy link

csh0101 commented Jan 25, 2024

And should be fixed by #3450并且应该由#3450修复

volar 1.82.7 is not fix it.

@mystic3333
Copy link

helpful, it has solve the problem,

@simaotwx
Copy link

I'm having this weird issue with the standard src if I build in oven/bun:

src/main.ts(6,17): error TS2307: Cannot find module '@/App.vue' or its corresponding type declarations.

It should find App.vue, I verified with find that it exists, but it still is not doing it.
It works on my host, which is weird.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants