tsconfig has set paths but doesn't compile alias

3.5k views Asked by At

When I compiled the code using tsc, I found that my alias name had not been converted, but I had already configured Paths,Here is 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"]
}

One of the compiled file parts of the code is 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");

Where is my code wrong

Thanks~~~

1

There are 1 answers

0
bayu On

you probably have to install additional dependencies for that like module-alias or tsconfig-paths

In my opinion, it would be easier to have the path resolved during the compilation but as the TS team says, it gets complicated in some environment with symlink usage.