一、找到项目下的 tsconfig.json
二、添加如图所示baseUrl和paths
文章来源地址https://www.toymoban.com/news/detail-520043.html
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"module": "ESNext",
"moduleResolution": "Node",
"strict": true,
"jsx": "preserve",
"resolveJsonModule": true,
"isolatedModules": true,
"esModuleInterop": true,
"lib": ["ESNext", "DOM"],
"skipLibCheck": true,
"noEmit": true,
//解析非相对模块的基础地址,默认是当前目录
"baseUrl": "./",
//路径映射,相对于baseUrl
"paths": {
"@/*": ["./src/*"]
},
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.node.json" }]
}
三、找到vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path' //引入path模块
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
vue: "vue/dist/vue.esm-bundler.js",
'@': path.resolve(__dirname, 'src'), //配置@路径
}
}
})
文章来源:https://www.toymoban.com/news/detail-520043.html
到了这里,关于vite + ts 找不到模块@/xxxx 或其相应的类型声明的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!