首页 > 解决方案 > typescript repo build 在我的机器上失败,但在 ubuntu docker 中通过

问题描述

我有一个 typescript repo 无法在我的机器上构建并出现错误...

$ tsc --pretty -p tsconfig.json
../../../../../../node_modules/@types/graphql/subscription/subscribe.d.ts:17:12 - error TS2304: Cannot find name 'AsyncIterator'.

17 ): Promise<AsyncIterator<ExecutionResult> | ExecutionResult>;
              ~~~~~~~~~~~~~


../../../../../../node_modules/@types/graphql/subscription/subscribe.d.ts:29:12 - error TS2304: Cannot find name 'AsyncIterable'.

29 ): Promise<AsyncIterable<any>>;
              ~~~~~~~~~~~~~


error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@types/graphql当我通过 grep 时,我找不到任何提及node_modules。我确实AsyncIterator在打字稿模块中找到了......

当我在 ubuntu 的 docker 容器中运行构建时,它通过了,但是在我的本地 OSSierra 机器上我收到了这个错误。我在网上找到了修复程序,说要在 中的库中添加“esnext” tsconfig.json,这似乎确实有效,但是这个 repo 不在我的控制之下,我仍然无法解释为什么会发生这种情况。有任何想法吗?

标签: node.jstypescriptnpm

解决方案


我们通过从父目录(在我们的例子中是主目录)中删除一个流氓 node_modules 文件夹来解决它。

显然打字稿/节点的模块解析在父目录中查找更多“信息”,也许其他人有更好的解释:)


推荐阅读