tsConfig 无法解析“@/*”路径

问题描述 投票:0回答:1

我正在尝试为“./src/components”创建一个路径别名,该别名在 Vite 中有效,但在 tsConfig 文件中无效。我已经尝试了 Stackoverflow 上的所有解决方案,但没有成功。

tsConfig.js

{
  "compilerOptions": {
    "target": "ES2020",
    "useDefineForClassFields": true,
    "module": "ESNext",
    "lib": ["ES2020", "DOM", "DOM.Iterable"],
    "baseUrl": "./src",
    "paths": {
      "@components/*": ["src/components/*"]
    },
    "skipLibCheck": true,

    /* Bundler mode */
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "preserve",

    /* Linting */
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true
  },
  "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"],
  "references": [{ "path": "./tsconfig.node.json" }]
}

项目树

错误信息

vue.js path vite tsconfig
1个回答
0
投票

我认为你必须这样做:

import TextInput from "@/components/core/TextInput.vue"

你被想念了/在@之后

© www.soinside.com 2019 - 2024. All rights reserved.