Vue3解决找不到模块@/components/xxx.vue或其相应的类型声明ts文件(2307)问题
作者:小徐敲java
这篇文章主要介绍了Vue3解决找不到模块@/components/xxx.vue或其相应的类型声明ts文件(2307)问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
问题
1:如果没有这个env.d.ts文件
就新建
declare module "*.vue" { import { DefineComponent } from "vue"; const component: DefineComponent<{}, {}, any>; export default component; }
2:如果有tsconfig.json文件
但是还是一样报错,就需要include读取文件env.d.ts文件
3:如果需要使用@简写访问src
如下3-1:如果没有这个tsconfig.json文件,就新建
{ "compilerOptions": { "target": "esnext", "useDefineForClassFields": true, "module": "esnext", "moduleResolution": "node", "strict": true, "jsx": "preserve", "sourceMap": true, "resolveJsonModule": true, "esModuleInterop": true, "lib": ["esnext", "dom"], "baseUrl": "./", "allowJs": true, "forceConsistentCasingInFileNames": true, "allowSyntheticDefaultImports": true, "strictFunctionTypes": false, "noUnusedLocals": true, "noUnusedParameters": true, "experimentalDecorators": true, "noImplicitAny": false, "skipLibCheck": true, "paths": { "@/*": ["src/*"] }, "types": [ // "@intlify/unplugin-vue-i18n/types", "vite/client" // "element-plus/global", // "@types/qrcode", // "vite-plugin-svg-icons/client" ], "outDir": "target", // 请保留这个属性,防止tsconfig.json文件报错 "typeRoots": ["./node_modules/@types/", "./types"] }, "include": [ "src", "types/**/*.d.ts", "src/types/auto-imports.d.ts", "src/types/auto-components.d.ts" ], "exclude": ["dist", "target", "node_modules"] }
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。