简体   繁体   English

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

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

I am trying to work with TinCanJS library in angular 6我正在尝试使用 angular 6 的 TinCanJS 库

github project github项目

I installed the package using npm install tincanjs --save我使用npm install tincanjs --save安装了该软件包

I imported the files in angular.json as follow:我在 angular.json 中导入文件如下:

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

I also tried as follow:我也试过如下:

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

In my app component I imported the tincan library as plain javascript because it has not type script as follow:在我的应用程序组件中,我将 tincan 库作为纯 javascript 导入,因为它没有键入脚本,如下所示:

import * as TinCan from 'tincanjs';

When I build the project using ng serve I keep getting the following error:当我使用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'

The TincanJS libarary has a dependency on the xhr2. TincanJS 库依赖于 xhr2。 I have checked the physical folder and the xhr2.js file exists in the right location.我已经检查了物理文件夹,并且 xhr2.js 文件存在于正确的位置。

I was wondering what am i doing wrong?我想知道我做错了什么? Can you help你能帮我吗

remove the xhr2删除xhr2

it should be,它应该是,

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

For declaration, instead of对于声明,而不是

import * as TinCan from 'tincanjs';

use

declare const TinCan: any;

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

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