gzf6
V2EX  ›  Vue.js

请教, vite2 配置 alias, 可以正常使用,但 Vetur 提示报错

  •  
  •   gzf6 · Mar 8, 2021 · 3194 views
    This topic created in 1893 days ago, the information mentioned may be changed or developed.

    vite.config.ts 配置 alias:

    resolve: {
      alias: {
        '@': path.resolve(__dirname, './src')
      }
    },
    

    使用时可以找到文件,但 vscode 的 Vetur 会报如下错误:

    Cannot find module '@/xxx' or its corresponding type declarations.Vetur(2307)

    如何让它不报错并且可以在代码提示时自动使用 alias 呢?

    3 replies    2021-03-08 19:31:13 +08:00
    dewfall
        1
    dewfall  
       Mar 8, 2021   ❤️ 1
    ts 的话可以配置 compilerOptions.paths
    zhuweiyou
        2
    zhuweiyou  
       Mar 8, 2021   ❤️ 1
    js 的话 也可以 jsconfig.json, 配置同楼上
    gzf6
        3
    gzf6  
    OP
       Mar 8, 2021
    @dewfall 设置了下面的可以了
    ```
    "paths": {
    "@/*":["./src/*"]
    }
    ```
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   953 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 20:09 · PVG 04:09 · LAX 13:09 · JFK 16:09
    ♥ Do have faith in what you're doing.