将fast.com API与Angular一起使用

问题描述

我是新手。我正在建立一个速度最快的网站作为辅助项目,并决定在我的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。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...