【发布时间】:2020-12-22 22:15:41
【问题描述】:
我是角度新手。我正在构建一个 speedtest 网站作为一个辅助项目,并决定使用 fast.com API. 在我的 component.ts 中,我包含以下内容:
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'
有人知道为什么会这样吗?
【问题讨论】:
标签: node.js angular speed-test