我正在尝试使用angular 6中的TinCanJS库
我使用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文件存在于正确的位置。
我想知道我做错了什么?你能帮上忙吗
发布于 2019-01-11 17:08:08
删除xhr2
它应该是,
"scripts": [
"node_modules/tincanjs/build/tincan-min.js"
]用于声明,而不是
import * as TinCan from 'tincanjs';使用
declare const TinCan: any;https://stackoverflow.com/questions/54142874
复制相似问题