【问题标题】:tsconfig has set paths but doesn't compile aliastsconfig 已设置路径但不编译别名
【发布时间】:2021-07-16 07:32:05
【问题描述】:

我用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"]
}

代码的编译文件部分之一在这里

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");

我的代码哪里错了

谢谢~~~

【问题讨论】:

  • 请注意大小写正确。

标签: typescript tsconfig tsconfig-paths


【解决方案1】:

您可能需要为此安装额外的依赖项,例如 module-aliastsconfig-paths

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

【讨论】:

    猜你喜欢
    • 2020-03-29
    • 2023-03-18
    • 2020-12-05
    • 1970-01-01
    • 2019-07-20
    • 2022-01-01
    • 2020-09-04
    • 1970-01-01
    • 2020-01-27
    相关资源
    最近更新 更多