解决Cannot find module ‘@/score/test/index.vue‘ or its corresponding type declarations.的报错

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "noImplicitThis": true,
    "baseUrl": ".",
    "types": ["webpack-env"],
    "paths": {
      "@/*": ["src/*"]
    },
    "lib": ["esnext", "dom", "dom.iterable", "scripthost"]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "src/**/*.d.ts",
    "src",
    "src/typings/*.d.ts"
  ],
  "exclude": ["node_modules"]
}

注意还应安装@types/webpack-env

npm install --save-dev @types/webpack-env

检查tsconfig.json文件,注意tsconfig.json不要与tsconfig.app.json冲突,可以将其合并为上文的代码,也可以分开为两个

tsconfig.json:

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "noImplicitThis": true,
    "baseUrl": ".",
    "types": ["webpack-env"],
    "paths": {
      "@/*": ["src/*"]
    },
    "lib": ["esnext", "dom", "dom.iterable", "scripthost"]
  },
  "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "src/**/*.d.ts", "src/typings/*.d.ts"],
  "exclude": ["node_modules"]
}

tsconfig.app.json

{
  "extends": "./tsconfig.json",
  "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
  "compilerOptions": {
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}

这个错误是由于无法找到模块或其对应的类型声明文件引起的。根据引用\[1\]和引用\[2\]的内容,可能是由于路径的问题导致的。在VueTypeScript项目中,使用动态导入模块时,TypeScript无法正确解析路径,从而导致找不到模块或类型声明文件。 为了解决这个问题,你可以按照引用\[3\]的建议,在Vue项目的根目录下创建一个名为typings.d.ts的文件,并在其中添加以下内容: ```typescript declare module '*.vue' { import { DefineComponent } from 'vue'; const component: DefineComponent<{}, {}, any>; export default component; } ``` 这样做可以为Vue的单文件组件添加类型声明,帮助TypeScript正确解析路径并找到对应的模块和类型声明文件。 #### 引用[.reference_title] - *1* [Cannot find module ‘@/components/test1.helloworld/test1.vue‘ or its corresponding type ...](https://blog.csdn.net/qubes/article/details/120807029)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [Cannot find module ‘@/views/test/index.vue‘ or its corresponding type declarations.ts(2307)的原因](https://blog.csdn.net/m0_57996540/article/details/130726601)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值