- Vue Cannot find module ‘node-sas
- 如何解决Cordova报错: Cannot find modul
- Module build failed: Error: Cann
- 编译报错:Error: Cannot find module '
- eslint prettier 不同格式
- ionic3 Cordova Cannot find modul
- 使用vue-cli 生成的webpack 项目,使用scss引入
- vue-cli@3.0使用vue-cli-plugin-cube
- ReactNative 新建项目,run后报错cannot fi
- webpack5下使用webpack-dev-server不能正
vue3+ts报错:Cannot find module ‘@/views/xxx.vue‘ or its corresponding type declarations

在Vue的TypeScript项目中,使用const test = () => import('@/views/login')语法动态导入模块时,可能会出现类型声明文件找不到的错误。这是由于TypeScript无法正确解析动态导入的路径而导致的。
尽管你在项目中没有遇到问题,但TypeScript的类型检查器仍然会发出警告或错误,因为它无法找到相应的类型声明文件。
要解决这个问题,你可以在Vue项目的根目录下创建一个env.d.ts(或者其他任何你喜欢的名称)的文件,并在其中添加以下内容:
declare module '*.vue' {
import { DefineComponent } from 'vue';
const component: DefineComponent<{}, {}, any>;
export default component;
}
在tsconfig.json 里引入env.d.ts
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx",
"./global.d.ts",
"./env.d.ts"
],
重启项目即可
网友评论