在我的一个vue3 + typescript的项目中,使用@/components时vscode会报错,当不使用@表示路径时不报错。(首先确定路径正确)
报错内容:
Cannot find module '@/components/HelloWorld.vue' or its corresponding type declarations.
解决方法:
第一步:需要在 tsconfig.json 中指定 @ 对应的path:
// tsconfig.json
{
// ...
"compilerOptions": {
// ...
"paths": {
"@/*": [
"./src/*"
],
}
}
//...
}
第二步:配置vite.config.ts
import path from 'path'
export default defineConfig({
resolve:{
alias:{
'@':path.resolve('./src')
}
}
})
611

被折叠的 条评论
为什么被折叠?



