[Unhandled promise rejection: ReferenceError: Can't find variable: performance]
a-zen opened this issue · comments
Hi,
I tried to use the library (version 1.2.0) inside my Expo project but when calling addToast I get the following error:
[Unhandled promise rejection: ReferenceError: Can't find variable: performance]
- node_modules/react-native-rooster/build/index.js:346:10 in now
- node_modules/react-native-rooster/build/index.js:171:32 in kickoff
- node_modules/react-native-rooster/build/index.js:245:22 in start
- node_modules/react-native-rooster/build/index.js:4508:13 in _start
* http://192.168.3.2:19001/node_modules/expo/AppEntry.bundle?platform=android&dev=true&minify=false&hot=false:140653:23 in _merge
* [native code]:null in _merge
The relevant code from the index.js is the following:
var now = function () { return performance.now(); };
Now I know this is the compiled TypeScript Code but I'm not seeing a require or import for performance-now anywhere.
The module performance-now is installed in my node_modules.
I could successfully run the example from the repository. As it doesn't use Expo I'm wondering if this is the cause.
Any idea?
Thank you.
Just played with the compiled index.js a little bit and replacing the performance call with the following fixes it:
var now = require("performance-now");
Thanks for your report. I'm gonna see which library is using "performance-now" 😄 because it isn't a direct dependency
You're right this is indeed strange. With yarn list
performance-now seems to be a root dependency.
I look at the yarn.lock and it seems the dependencies are like this:
| jest-runner, jest-runtime, @jest/core, jest-cli
|- jest-config
|- jest-environment-jsdom
|- jsdom
|- request
|- performance-now
npm list
shows it correctly.
Oh sorry my bad I read the code completely wrong. So the code I referred to in the bundle comes form the @react-spring
package. And there they actually call the web standard:
https://developer.mozilla.org/en-US/docs/Web/API/Performance/now
So I'm not sure why it can't find the variable in my project.
@a-zen , many thanks!! I've just released a new version and I think it can fix on Expo. Can you give it a try?
yarn add react-native-rooster@next
EDIT: Not yet. I'm still debugging why this error is occurring even when I add import 'performance-now'
I think I put you on the wrong track. So performance-now is just used somewhere in jest and that is fine.
But the react-spring uses the standard web api performance and this can't be find when using Expo.
I'm not sure if a polyfil is needed for this or not. Also I'm not sure why it works without Expo but fails with Expo.
It's been quite busy here, but this week I had time to take a look into this bug, plus as this library is new I had time to test it in production in my apps. I've recently released the 1.3.0 which does not include react-spring dependency anymore replaced by RN's Animated API which also dropped RNRooster's size from 1.18MB to 77kB. I decided to remove it, because I experienced a few performance issues in my apps.
In addiction to that, I tested 1.3.0 in Expo and it is working perfectly.
I'll close this issue for now.
Thanks for your patience! 😄