配置別名
在 vite.config.ts
import { defineConfig } from "vite";
import path from "path";
export default defineConfig({
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
},
}
});
問(wèn)題一
Cannot find module 'path' or its corresponding type declarations.ts、Cannot find module 'path' or its corresponding type declarations.ts
要安裝@types/node
問(wèn)題二
Module '"path"' can only be default-imported using the 'esModuleInterop' flag
tsconfig.node.json 要增加
{
"compilerOptions": {
"esModuleInterop": true
},
}
問(wèn)題三
Cannot find module '@/store' or its corresponding type declarations.ts
識(shí)別不了@會(huì)導(dǎo)致代碼提示失效,要修改 tsconfig.json
{
"compilerOptions": {
"paths": {
"@/*": ["src/*"]
}
},
}