首页 > 解决方案 > tsconfig 已设置路径但不编译别名

问题描述

使用tsc编译代码的时候发现我的别名并没有转换,但是我已经配置了Paths,这里是tsconfig.json

{
  "compilerOptions": {
    // https://github.com/TypeStrong/ts-loader/issues/1061
    "target": "ES5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "paths": {
      "@/*": ["./src/*"],
      "doc/*": ["./site/*"],
      "docs/*": ["./site/Components/*"],
      "ethan/*": ["./src/*"],
      "ethan": ["./src/index.ts"]
    },
    "rootDir": "src",
    "outDir": "publish/css",
    "experimentalDecorators": true,
    "allowJs": true,
    "checkJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "CommonJS",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "jsx": "react",
    "strict": false,
    "noImplicitAny": false,
    "suppressImplicitAnyIndexErrors": true,
    "baseUrl": "./",
    "strictNullChecks": false,
    "alwaysStrict": false,
    "downlevelIteration": true,
  },
  "include": ["src"],
  "exclude": ["node_modules", "ssh-client", "webpack", "scripts", "docs-pages","publish"]
}

代码的编译文件部分之一是here

var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLocale = exports.setLocale = void 0;
// @ts-nocheck 
var objects_1 = require("@/utils/objects");

我的代码哪里错了

谢谢~~~

标签: typescripttsconfigtsconfig-paths

解决方案


您可能必须为此安装其他依赖项,例如module-aliastsconfig-paths

在我看来,在编译期间解析路径会更容易,但正如 TS 团队所说,在某些使用符号链接的环境中它会变得复杂。


推荐阅读