You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

tsConfig无法解析@components路径别名问题求助

问题:Vite中@components路径别名正常生效,但TypeScript无法解析

我给./src/components配置了@components路径别名,这个别名在Vite里能正常使用,但TypeScript配置文件无法解析它。我试过StackOverflow上的所有解决方案,都没解决问题。

相关信息

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2020",
    "useDefineForClassFields": true,
    "module": "ESNext",
    "lib": ["ES2020", "DOM", "DOM.Iterable"],
    "baseUrl": "./src",
    "paths": {
      "@components/*": ["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" }]
}

项目目录结构

项目目录结构

报错信息

中文翻译:无法找到模块“@components/Button”或其相应的类型声明。
报错信息


内容的提问来源于stack exchange,提问作者Achraf FAWZI

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 09:32:38