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

use*_*486 -2 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'.
Run Code Online (Sandbox Code Playgroud)

我在 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```
Run Code Online (Sandbox Code Playgroud)

ale*_*pls 5

FileReadableStream类型在定义dom打字稿库。

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

{
  ...
  "compilerOptions": {
    "lib": [
      ...
      "dom"
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)