vite配置踩坑实录

作者: 小遁哥 | 来源:发表于2023-07-10 10:46 被阅读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/*"]
        }
      },
    
    }
    

    相关文章

      网友评论

        本文标题:vite配置踩坑实录

        本文链接:https://www.haomeiwen.com/subject/khyeudtx.html