程序员前端便利店让前端飞

vite配置踩坑实录

2023-07-10  本文已影响0人  小遁哥

配置别名

在 vite.config.ts

import { defineConfig } from "vite";

import path from "path";

export default defineConfig({
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
    },
  }
});

问题一

Cannot find module 'path' or its corresponding type declarations.ts、Cannot find module 'path' or its corresponding type declarations.ts

要安装@types/node

问题二

Module '"path"' can only be default-imported using the 'esModuleInterop' flag

tsconfig.node.json 要增加

{
  "compilerOptions": {
    "esModuleInterop": true
  },
}

问题三

Cannot find module '@/store' or its corresponding type declarations.ts

识别不了@会导致代码提示失效,要修改 tsconfig.json

{
  "compilerOptions": {
    "paths": {
      "@/*": ["src/*"]
    }
  },

}
上一篇下一篇

猜你喜欢

热点阅读