我为运行 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:workspacescustomernode_modulesminigetdist'
ERROR in ./node_modules/miniget/dist/index.js
Module not found: Error: Can't resolve 'https' in 'D:workspacescustomernode_modulesminigetdist'
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';
~~~~~~
问题是什么?
这是由浏览器中不可用的节点模块的依赖关系引起的。将这些添加到您的 package.json 文件中。
删除你的 node_modules 文件夹并运行这些命令
转到您的
node_modules/ytdl-core/typings
文件夹并从index.d.ts
中删除这些行