接收TS2304:找不到名称“文件” | TS2304:运行“ npm run tsc”命令时找不到名称“ ReadableStream”

时间:2019-03-25 14:31:36

标签: node.js npm tsc npm-start

我有一个使用“ watson-developer-cloud”模块的nodejs应用程序。使用“ npm install --save watson-developer-cloud”包含了此模块。

运行“ npm run tsc”时,我看到以下问题。

node_modules/ibm-cloud-sdk-core/lib/content-type.d.ts(4,35): error TS2304: Cannot find name 'File'.
node_modules/ibm-cloud-sdk-core/lib/content-type.d.ts(4,42): error TS2304: Cannot find name 'ReadableStream'.

我正在Mac上运行它。 节点版本10.15.3。 我发现一些文章要求设置节点bin目录的路径并重新加载终端。 我做到了-尽管又遇到了同样的问题。

node_modules/ibm-cloud-sdk-core/lib/content-type.d.ts(4,35): error TS2304: Cannot find name 'File'.
node_modules/ibm-cloud-sdk-core/lib/content-type.d.ts(4,42): error TS2304: Cannot find name 'ReadableStream'.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! my-program@1.0.0 tsc: `tsc`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the my-program@1.0.0 tsc script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-03-25T14_29_06_333Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! my-program@1.0.0 build: `npm run tsc && npm run tslint`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the my-program@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-03-25T14_29_06_351Z-debug.log
ERROR: Service 'my-program' failed to build: The command '/bin/sh -c npm run build' returned a non-zero code: 2```

1 个答案:

答案 0 :(得分:0)

FileReadableStream类型在dom TypeScript库中定义。

尝试将其添加到您的tsconfig.json

{
  ...
  "compilerOptions": {
    "lib": [
      ...
      "dom"
    ]
  }
}