tsconfig.json compilerOptions 路径不解析

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

我正在用打字稿写一些代码,内容如下

tsconfig.json

{
  "compilerOptions": {
    "baseUrl": "./src",
    "target": "esnext",
    "esModuleInterop": true,
    "downlevelIteration": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "paths": {
      "@utils": [
        "utils/*"
      ]
    }
  },
  "include": [
    "./src/**/*.ts"
  ]
}

以及以下目录树:

.
├── dist
│   ├── main.js
│   ├── preload.js
│   └── renderer.js
├── src
│   ├── main
│   │   └── index.ts
│   ├── preload
│   │   └── index.ts
│   ├── renderer
│   │   └── index.ts
│   └── utils
│       ├── constants.ts
│       ├── hotkeys
│       │   └── index.js
│       └── logger
│           └── index.ts
├── tsconfig.json
├── .gitignore
├── README.md
└── package.json

src/main/index.ts
中,考虑到
src/utils/logger/index.ts
文件中的
@utils/logger/index.ts
键,我正在尝试通过应该有效的
compilerOptions.paths
别名导入
tsconfig.json
文件;但我收到以下错误:

error TS2307: Cannot find module '@utils/logger/index' or its corresponding type declarations.

这不是创建别名的正确方法吗?如果不是我应该怎么做?

我也在使用 esbuild,所以如果没有解决方案

tsconfig.json
esbuild 解决方案将是最好的!

我已经查看了我可以在 Google 上找到的所有解决方案,但没有一个对我有用。

typescript alias tsconfig
© www.soinside.com 2019 - 2024. All rights reserved.