简体   繁体   中英

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

I am trying to work with TinCanJS library in angular 6

github project

I installed the package using npm install tincanjs --save

I imported the files in angular.json as follow:

"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:

import * as TinCan from 'tincanjs';

When I build the project using ng serve I keep getting the following error:

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. I have checked the physical folder and the xhr2.js file exists in the right location.

I was wondering what am i doing wrong? Can you help

remove the 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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