给出一个错误"URL不是构造函数“
我的代码https://codesandbox.io/s/patient-dust-do1d8?file=/src/App.js
库https://www.npmjs.com/package/network-speed
import React from "react";
const NetworkSpeed = require('network-speed');
const testNetworkSpeed = new NetworkSpeed();
async function getNetworkDownloadSpeed() {
const baseUrl = "http://eu.httpbin.org/stream-bytes/50000000";
const fileSizeInBytes = 50000000;
const speed = await testNetworkSpeed.checkDownloadSpeed(
baseUrl,
fileSizeInBytes
);
console.log(speed);
}
export default function App() {
console.log(NetworkSpeed)
return (
<div className="App">
<button onClick={() => getNetworkDownloadSpeed()}>34</button>
</div>
);
}发布于 2020-08-04 10:28:00
你不能用那个包裹来反应。
它不适合在浏览器中使用,而是在Node.js (where you have the http and https builtin modules, for one)中使用。
https://stackoverflow.com/questions/63244914
复制相似问题