繁体   English   中英

Angular 6 - 找不到模块:错误:无法解析“http”

[英]Angular 6 - Module not found: Error: Can't resolve 'http' in

我正在尝试使用 angular 6 的 TinCanJS 库

github项目

我使用npm install tincanjs --save安装了该软件包

我在 angular.json 中导入文件如下:

"scripts": [
              "./node_modules/tincanjs/node_modules/xhr2/lib/xhr2.js",
              "./node_modules/tincanjs/build/tincan-min.js"
            ]

我也试过如下:

"scripts": [
    "./node_modules/xhr2/lib/xhr2.js",
    "./node_modules/tincanjs/build/tincan-min.js"
]

在我的应用程序组件中,我将 tincan 库作为纯 javascript 导入,因为它没有键入脚本,如下所示:

import * as TinCan from 'tincanjs';

当我使用ng serve构建项目时,我不断收到以下错误:

ERROR in ./node_modules/tincanjs/node_modules/xhr2/lib/xhr2.js
Module not found: Error: Can't resolve 'http' in 'C:\Dev Projects\xAPI Angular Example\xAPIExample\node_modules\tincanjs\node_modules\xhr2\lib'
ERROR in ./node_modules/tincanjs/node_modules/xhr2/lib/xhr2.js
Module not found: Error: Can't resolve 'https' in 'C:\Dev Projects\xAPI Angular Example\xAPIExample\node_modules\tincanjs\node_modules\xhr2\lib'
ERROR in ./node_modules/tincanjs/node_modules/xhr2/lib/xhr2.js
Module not found: Error: Can't resolve 'os' in 'C:\Dev Projects\xAPI Angular Example\xAPIExample\node_modules\tincanjs\node_modules\xhr2\lib'

TincanJS 库依赖于 xhr2。 我已经检查了物理文件夹,并且 xhr2.js 文件存在于正确的位置。

我想知道我做错了什么? 你能帮我吗

删除xhr2

它应该是,

"scripts": [
    "node_modules/tincanjs/build/tincan-min.js"
]

对于声明,而不是

import * as TinCan from 'tincanjs';

declare const TinCan: any;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM