Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

universal-speedtest in react native error #21

Open
leo-lucky-hub opened this issue Jun 2, 2022 · 28 comments
Open

universal-speedtest in react native error #21

leo-lucky-hub opened this issue Jun 2, 2022 · 28 comments
Labels
bug Something isn't working

Comments

@leo-lucky-hub
Copy link

error: ERROR: Unable to resolve module perf_hooks from file '../node_modules/universal-speedtest/dist/Speedtest.js':perf_hooks could not be found within the project or in these directories: node_modules
Object.defineProperty(exports, "--esModule", { value:true });
exports.Speedtest = void 0;
const perf_hooks_1 = require("perf_hooks");
const path = require("path");

@leo-lucky-hub leo-lucky-hub added the bug Something isn't working label Jun 2, 2022
@karelkryda
Copy link
Owner

karelkryda commented Jun 2, 2022

Hi,
are you using the latest version of Universal Speedtest? I addressed this issue when I released version, I think, 2.1 2.0.1.

I admit I'm not able to say where the problem might be, but I did a quick Google search and got this result from Stack Overflow.

Please try searching Google for a problem with perf_hooks in React. It looks like this is a fairly long-standing problem.

Let me know if you've been able to fix the problem.

Bye

@leo-lucky-hub
Copy link
Author

Thank you for your answer。
Use the following command to install and get version 2.0.5
npm install --save universal-speedtest

How can I get the latest version

@karelkryda
Copy link
Owner

It's correct, it's the latest version

@leo-lucky-hub
Copy link
Author

According to your prompt, the problem has not been solved,
I am using react native, not react, what can I do to solve this problem

@karelkryda
Copy link
Owner

As I say, it will probably be a problem with React native. Being you, I would try searching on Google to find out how to fix the error perf_hooks in React native and if you do not find any solution, I would try to write to some counseling center (such as Stack Overflow).

Currently it seems that the problem is more with React native, unfortunately I have never worked with it and I am not able to say where the problem might be.

If a Universal Speedtest modification is required, I have no problem with that, but at the moment the problem seems to be elsewhere.

@leo-lucky-hub
Copy link
Author

Thank you for your answer. I try to solve the problem. I have another question. I want to call the fast.com API to get the following details. Does this API support it?
speed

@karelkryda
Copy link
Owner

Hi,
currently there is support only for Cloudflare test and Ooakla Speedtest.

I think there were some difficulties with the implementation of the test from Fast.com.
I could try to look at it's implementation again if you want.

@leo-lucky-hub
Copy link
Author

If your time permits, implement Fast.com Get information. That's great

@karelkryda
Copy link
Owner

Okay, I'll try. I'm not sure exactly where the problem was, truth be told.

@leo-lucky-hub
Copy link
Author

Thank you. Good luck

@leo-lucky-hub
Copy link
Author

hi,Has the function been implemented?

@karelkryda
Copy link
Owner

No, not yet. I'm away from home for an extended period of time. I will be coming back around 20.6.. And honestly, I feel like Fast.com test couldn't be implemented because of the way the test works. We'll see...

@leo-lucky-hub
Copy link
Author

Thanks, then I want to ask another question。
Universal-speedtest uses the code in @type/node, can it be implemented without the code in @type/node? Because react native is not based on node, it will appear that perf_hooks cannot be used

@karelkryda
Copy link
Owner

I use the performance.now() function, which measures the time of the test run and calculates the speed. There was an error at release and therefore I have to import perf_hooks. This solved the problem with the performance.now() function, and the library works fine.

Truth be told, I don't understand why this should cause you problems. This function should be directly part of Node.js, right? So I'm not sure about that, but I have that feeling. I can take a look.

@karelkryda
Copy link
Owner

Wait. Now I notice that you write that React native is not based on Node.js. What does it work on?

@leo-lucky-hub
Copy link
Author

React Native is a JavaScript framework for writing real, natively rendering mobile applications for iOS and Android. It’s based on React, Facebook’s JavaScript library for building user interfaces, but instead of targeting the browser, it targets mobile platforms.

@yuqiuqi
Copy link

yuqiuqi commented Nov 21, 2022

@luckyyaxianzhi
error: ERROR: Unable to resolve module perf_hooks from file
I also encountered this problem, did you solve it?

@karelkryda
Copy link
Owner

Hello,
I am currently rewriting the library to version 3.0.0. This update will include the replacement of performance.now() with Date.now(). With this step, you should both be able to use this library in React native (I firmly believe in this) 😉.

karelkryda added a commit that referenced this issue Dec 8, 2022
 - usage of `Date.now()` instead of `performance.now()` (hopefully solves #21)
 - more economical code (optimized calls, etc.)
 - used better endpoint to get speedtest.net servers
 - other useful changes
@karelkryda
Copy link
Owner

Hi again,
I pushed the last development version to the build branch. You can now try it with:

npm install --save github:karelkryda/universal-speedtest#build


Please let me know if this solved the problem, however when I tried it online I got an error again due to perf_hooks but this time in the urllib library.
Let's see...

@IchordeDionysos
Copy link

I try to run it inside a web worker and I get the error when importing node_modules/universal-speedtest/dist/index.js:

Uncaught ReferenceError: exports is not defined
    at index.js:2:23
    at speedtest.js:1:30
    at _i (worker.js:1:159)
    at onmessage (worker.js:1:90)

@karelkryda
Copy link
Owner

@IchordeDionysos That's weird. I'm guessing it's also React Native, right? Have you tried version 3.0.0 as I wrote in the comment above?

@IchordeDionysos
Copy link

@karelkryda It, unfortunately, does not work ...

Steps to reproduce:

  1. Create the following package.json:
{
  "scripts": {
    "start": "http-server ."
  },
  "dependencies": {
    "universal-speedtest": "github:karelkryda/universal-speedtest#build"
  },
  "devDependencies": {
    "http-server": "^14.1.1"
  }
}
  1. Add the following index.html file:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Universal Speedtest</title>
</head>
<body>
  <script src="node_modules/universal-speedtest/dist/index.js"></script>
</body>
</html>
  1. Install the dependencies
  2. Run the website using yarn start

The following error will be shown:

Uncaught ReferenceError: exports is not defined
    at index.js:16:23

For example, a library like axios generates different versions for different environments:
https://github.com/axios/axios/tree/v1.x/dist

They do this using rollup:
https://github.com/axios/axios/blob/v1.x/rollup.config.js

I really liked the design of the library when I saw it, would be cool if it would be available across platforms.

@uthmanzaman
Copy link

is there a solution for this?

@karelkryda
Copy link
Owner

Hey, guys,
I just wanted to let you know that I'm currently trying to get Rollup up and running, see @IchordeDionysos's idea. Unfortunately I haven't come across this tool yet (and also Axios is written in JavaScript and Universal Speedtest is written in TypeScript), so it's a bit of a problem for me. In fact, there is also a problem with the urllib library, because it is not compatible with React Native (it uses perf-hooks, which I tried to get rid of in version 3.0.0, but thanks to urllib this error still occurs). I don't know if Rollup can solve this or not 🤷🏻‍♂️.
I'm also trying not to completely break the whole library, because then it would be pretty useless 😅.

If anyone has worked with this tool and knows how to use it properly or if you have any other ideas, feel free to let me know 🙂 .

Thanks for your patience and ideas

@karelkryda
Copy link
Owner

Hi, guys,
I just released the release candidate of version 3.0.0.
You can install and test the library using:

npm install --save universal-speedtest@next

The new documentation can be found here: https://karel-kryda.gitbook.io/universal-speedtest/v/3

Could someone please test for me if the library is now compatible with React Native? Unfortunately, I have never worked with it and have not been able to get a test project up and running.

I hope everything will work as expected 😉.
Thank you in advance for your help

@Marcuspo
Copy link

Marcuspo commented Dec 1, 2024

Hi, guys, I just released the release candidate of version 3.0.0. You can install and test the library using:

npm install --save universal-speedtest@next

The new documentation can be found here: https://karel-kryda.gitbook.io/universal-speedtest/v/3

Could someone please test for me if the library is now compatible with React Native? Unfortunately, I have never worked with it and have not been able to get a test project up and running.

I hope everything will work as expected 😉. Thank you in advance for your help

image Hi, it's still not working with the new version.

@karelkryda
Copy link
Owner

@Marcuspo, Thank you for testing. I tried to make it compatible with the browsers too, but I couldn't find a solution.
Could you please try to remove the node: prefix in the mentioned file, see if this solves the problem?

Thank you in advance

@Marcuspo
Copy link

Marcuspo commented Dec 2, 2024

@Marcuspo, Thank you for testing. I tried to make it compatible with the browsers too, but I couldn't find a solution. Could you please try to remove the node: prefix in the mentioned file, see if this solves the problem?

Thank you in advance

image still not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants