Skip to content

Cannot find module 'file.vue' or its corresponding type declarations #4118

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

Closed
nethriis opened this issue Mar 19, 2024 · 10 comments
Closed

Cannot find module 'file.vue' or its corresponding type declarations #4118

nethriis opened this issue Mar 19, 2024 · 10 comments

Comments

@nethriis
Copy link

Good morning,
Everything was working fine until now, then suddenly, I opened my ./src/router/index.ts file and I got lots of errors telling me for my view imports for my router by example :

import HomeView from '@/views/Home.vue'

I have the error:

Cannot find module '@/views/Home.vue' or its corresponding type declarations.

And the same error in my ./src/main.ts with :

import App from './App.vue'

Only *.vue files are affected
Everything was working fine before, I don't know what happened in the meantime.

Here are my TypeScript configuration files:
tsconfig.app.json

{
  "extends": "@vue/tsconfig/tsconfig.dom.json",
  "include": ["env.d.ts", "src/**/*", "src/**/*.vue", "src/**/*.ts"],
  "exclude": ["src/**/__tests__/*"],
  "compilerOptions": {
    "composite": true,
    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",

    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}

tsconfig.node.json

{
  "extends": "@tsconfig/node20/tsconfig.json",
  "include": [
    "vite.config.*",
    "vitest.config.*",
    "cypress.config.*",
    "nightwatch.conf.*",
    "playwright.config.*"
  ],
  "compilerOptions": {
    "composite": true,
    "noEmit": true,
    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",

    "module": "ESNext",
    "moduleResolution": "Bundler",
    "types": ["node"]
  }
}

tsconfig.json

{
  "files": [],
  "references": [
    {
      "path": "./tsconfig.node.json"
    },
    {
      "path": "./tsconfig.app.json"
    }
  ]
}

I'm on Vue version 3.4.21

@arpadgabor
Copy link

Same issue here. Fixed it with allowJs: true in tsconfig, but we're now also seeing "type instantiation is infinitely deep" type of error with Hono, however 1.8.27 works fine.

@nethriis
Copy link
Author

Same issue here. Fixed it with allowJs: true in tsconfig, but we're now also seeing "type instantiation is infinitely deep" type of error with Hono, however 1.8.27 works fine.

I'm already on v1.8.27

@DemonQilin
Copy link

Same issue. Why did it happen?

tsconfig.app.json

{
  "extends": "@vue/tsconfig/tsconfig.web.json",
  "include": ["declarations/**/*.d.ts", "src/**/*", "src/**/*.vue", "src/**/*.json"],
  "exclude": ["src/**/__tests__/*"],
  "compilerOptions": {
    "lib": ["ES2017", "DOM", "DOM.Iterable"],
    "composite": true,
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    },
    "types": ["vitest/globals"]
  }
}

tsconfig.config.json

{
  "extends": "@vue/tsconfig/tsconfig.node.json",
  "include": ["vite.config.*", "vitest.config.*", "cypress.config.*", "playwright.config.*"],
  "compilerOptions": {
    "composite": true,
    "types": ["node"]
  }
}

tsconfig.vitest.json

{
  "extends": "./tsconfig.app.json",
  "include": ["declarations/**/*.d.ts", "src/**/*", "src/**/*.vue", "src/**/*.json"],
  "exclude": [],
  "compilerOptions": {
    "composite": true,
    "types": ["node", "vitest/globals"]
  }
}

tsconfig.json

{
  "files": [],
  "references": [
    {
      "path": "./tsconfig.config.json"
    },
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.vitest.json"
    }
  ]
}

@BTBMan
Copy link

BTBMan commented Mar 25, 2024

I noticed that the Vue-official plugin load typescript config file is different from the built-in typescript plugin, If the tsconfig.json has references field, they're loaded in a different order.

I don't know how to explain...

There are two tsconfig files, tsconfig.app.json and tsconfig.vitest.json, they both have "include": ["src"], If the tsconfig.app.json is set before the tsconfig.vitest.json, then open the .ts file, It loaded tsconfig.vitest.json but the .vue file is loaded tsconfig.app.json, If change the order of the references, The config file that .ts file and .vue file are change, too.

@BTBMan
Copy link

BTBMan commented Mar 25, 2024

I find this #2548, But It's not support for v2

@michaelangeloio
Copy link

this is also an issue for me

@BTBMan
Copy link

BTBMan commented May 29, 2024

@michaelangeloio Set the VSCode settings vue.server.hybridMode to false, That makes the order of loading the tsconfig in .ts and .vue the same.

@EtzBetz
Copy link

EtzBetz commented Jun 19, 2024

I also have this issue in JetBrains WebStorm

@catgoose
Copy link

I fixed this by creating src/vue.d.ts with:

declare module '*.vue';

@davidmatter
Copy link
Collaborator

Closing this one as many things have changed since 2.x. Feel free to create a new issue with a minimal reproduction if you're still having issues, thanks!

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

No branches or pull requests

8 participants