【问题标题】:Trouble converting project to Typescript paths将项目转换为 Typescript 路径时遇到问题
【发布时间】:2019-08-18 14:42:02
【问题描述】:

So I asked this question earlier today on how to use paths.

现在我正在尝试使用这种方法转换 this project

所以我先克隆它:

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 }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

想法?

Typescript Github 问题

Filed an Issue with Typescript here

【问题讨论】:

    标签: javascript node.js angular typescript npm


    【解决方案1】:

    将您的路径属性添加到 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/*"
          ]
        }
      }
    }
    

    【讨论】:

    • 刚刚仔细检查过 - AFAIK 它在 compilerOptions 部分...?
    • 你没看示例配置对象吗?它在 compilerOptions 部分
    • This is the config I'm converting。我首先创建了一个最小的 MVCE,以确保我有一些可以工作的东西。现在我正在尝试将其应用于另一个项目,但它不起作用......
    • 您是否尝试克隆该项目以查看它是否适用于您?您会注意到,在我链接的上一个答案中,我们必须删除 glob 模式才能使其正常工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-07
    • 2014-02-28
    • 2022-01-25
    • 1970-01-01
    • 2020-10-06
    • 2018-01-08
    相关资源
    最近更新 更多