1

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

Silagy
  • 3,053
  • 2
  • 27
  • 39

1 Answers1

1

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;
John Velasquez
  • 3,421
  • 2
  • 18
  • 23