首页 > 解决方案 > 将项目转换为 Typescript 路径时遇到问题

问题描述

所以我今天早些时候问了这个关于如何使用路径的问题

现在我正在尝试使用这种方法转换这个项目

所以我首先克隆它:

git clone git@github.com:fireflysemantics/validator.git

然后编辑paths设置,使其看起来像这样:

"baseUrl": "./",                          /* Base directory to resolve non-absolute module names. */
"paths": {
  "@fs": ["./src"], 
  "@test": ["./test"]
},                                        /* 

然后我尝试编辑src/container/error/index.ts它,使其看起来像这样:

export { ObjectErrors } from "@fs/container/error/ObjectErrors";
export { ValidationError } from "./ValidationError";

当我编译 Typescript 时仍然会产生这个错误:

src/container/error/index.ts:1:30 - 错误 TS2307:找不到模块 '@fs/container/error/ObjectErrors'。

1 从“@fs/container/error/ObjectErrors”导出 { ObjectErrors };~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

想法?

打字稿 Github 问题

在这里提出了 Typescript 的问题

标签: javascriptnode.jsangulartypescriptnpm

解决方案


将您的路径属性添加到 tsconfig 文件中的 compilerOptions。

  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ],
    "paths": {      
      "@app/*": [
        "./app/*"
      ]
    }
  }
}

推荐阅读