【问题标题】:Receiving TS2304: Cannot find name 'File' | TS2304: Cannot find name 'ReadableStream' when running "npm run tsc" command接收 TS2304:找不到名称“文件”| TS2304:运行“npm run tsc”命令时找不到名称“ReadableStream”
【发布时间】:2019-03-25 14:31:35
【问题描述】:

我有一个使用“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```

【问题讨论】:

    标签: node.js npm tsc npm-start


    【解决方案1】:

    FileReadableStream 类型在 dom TypeScript 库中定义。

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

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

    【讨论】:

      猜你喜欢
      • 2019-04-21
      • 1970-01-01
      • 2022-01-20
      • 2017-08-11
      • 2017-08-23
      • 1970-01-01
      • 2019-08-17
      • 2017-11-03
      • 2019-12-24
      相关资源
      最近更新 更多