【问题标题】:Cannot find module 'http' or its corresponding type declarations while I try include ytdl-core在我尝试包含 ytdl-core 时找不到模块“http”或其相应的类型声明
【发布时间】:2021-02-19 03:05:51
【问题描述】:

我为运行 npm install ytdl-core --save (https://www.npmjs.com/package/ytdl-core) 的 Angular 项目下载 ytdl-core。为了使用这个模块,我这样做:

import ytdl from 'ytdl-core';

ytdl(url);

当我启动 Angular 应用程序时,它会显示下一条消息:

ERROR in ./node_modules/miniget/dist/index.js
Module not found: Error: Can't resolve 'http' in 'D:\workspaces\customer\node_modules\miniget\dist'

ERROR in ./node_modules/miniget/dist/index.js
Module not found: Error: Can't resolve 'https' in 'D:\workspaces\customer\node_modules\miniget\dist'

    ERROR in node_modules/ytdl-core/typings/index.d.ts:2:33 - error TS2307: Cannot find module 'http' or its corresponding type declarations.
2   import { ClientRequest } from 'http';
                                  ~~~~~~

有什么问题?

【问题讨论】:

    标签: angular ytdl


    【解决方案1】:

    这是由浏览器中不可用的节点模块的依赖关系引起的。 将这些添加到您的 package.json 文件中。

    "browser": {
      "http": false,
      "https": false,
      "net": false,
      "path": false,
      "stream": false,
      "tls": false
    }
    

    删除你的 node_modules 文件夹并运行这些命令

    npm install
    npm install stream
    npm install --save-dev @types/node
    npm install ytdl-core --save
    

    转到您的node_modules/ytdl-core/typings 文件夹并从index.d.ts 中删除这些行

    import { ClientRequest } from 'http'; // Delete this
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-16
      • 2020-11-04
      • 2021-02-19
      • 2023-01-31
      • 2020-10-19
      • 2021-09-21
      • 2020-12-23
      相关资源
      最近更新 更多