问题描述
我是新手。我正在建立一个速度最快的网站作为辅助项目,并决定在我的component.ts中使用fast.com API.,其中包括以下内容:
constructor() {
const FastSpeedtest = require('fast-speedtest-api');
const speedtest = new FastSpeedtest({
token: 'myToken',// required
verbose: false,// default: false
timeout: 10000,// default: 5000
https: true,// default: true
urlCount: 5,// default: 5
bufferSize: 8,// default: 8
unit: FastSpeedtest.UNITS.Mbps,// default: Bps
proxy: 'http://optional:auth@my-proxy:123',// default: undefined
});
speedtest
.getSpeed()
.then((s) => {
console.log(`Speed: ${s} Mbps`);
})
.catch((e) => {
console.error(e.message);
});
}
但是当我运行ng serve
时,出现以下角度错误:
Failed to compile.
./node_modules/fast-speedtest-api/src/Api.js
Module not found: Error: Can't resolve 'http' in 'C:\Users\sacre\Documents\GitHub\speedtest\node_modules\fast-speedtest-api\src'
有人知道为什么会这样吗?
解决方法
已编辑
请参见Github issue - Angular Integration #4
这是与NodeJS一起使用的说明。由于它使用NodeJS API,因此无法在浏览器中正常运行。
基于不支持在运行角度的浏览器中运行此api。