question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[v4] TypeError: global.performance.now is not a function

See original GitHub issue

Bug

TypeError: global.performance.now is not a function

Environment info

Library Version
@gorhom/bottom-sheet ^4.1.5
react-native ^0.66.3
react-native-reanimated ^2.3.0
react-native-gesture-handler ^2.1.0

Steps To Reproduce

  • All installation steps for reanimated and gesture-handler have been done

Describe what you expected to happen:

  1. It works =)

Reproducible sample code

import React, {useCallback, useMemo, useRef} from 'react';
import {View, Text, StyleSheet, Button} from 'react-native';
import {BottomSheetModal, BottomSheetModalProvider} from '@gorhom/bottom-sheet';
import {
  gestureHandlerRootHOC,
  GestureHandlerRootView,
  NativeViewGestureHandler,
} from 'react-native-gesture-handler';

const App = () => {
  // ref
  const bottomSheetModalRef = useRef<BottomSheetModal>(null);

  // variables
  const snapPoints = useMemo(() => ['25%', '50%'], []);

  // callbacks
  const handlePresentModalPress = useCallback(() => {
    bottomSheetModalRef.current?.present();
  }, []);
  const handleSheetChanges = useCallback((index: number) => {
    console.log('handleSheetChanges', index);
  }, []);

  // renders
  return (
    <BottomSheetModalProvider>
      <View style={styles.container}>
        <Button
          onPress={handlePresentModalPress}
          title="Present Modal"
          color="black"
        />
        <BottomSheetModal
          ref={bottomSheetModalRef}
          index={1}
          snapPoints={snapPoints}
          onChange={handleSheetChanges}>
          <View style={styles.contentContainer}>
            <Text>Awesome 🎉</Text>
          </View>
        </BottomSheetModal>
      </View>
    </BottomSheetModalProvider>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: 24,
    justifyContent: 'center',
    backgroundColor: 'grey',
  },
  contentContainer: {
    flex: 1,
    alignItems: 'center',
  },
});

export default gestureHandlerRootHOC(App);

simulator_screenshot_B3D309C9-ED3D-430A-9C5C-23CC0FA861C1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:22 (1 by maintainers)

github_iconTop GitHub Comments

67reactions
origamihcommented, Dec 23, 2021

V2.3.1 Use patch-package and apply this patch:

diff --git a/node_modules/react-native-reanimated/src/reanimated2/core.ts b/node_modules/react-native-reanimated/src/reanimated2/core.ts
index 2e0c38a..6b134c6 100644
--- a/node_modules/react-native-reanimated/src/reanimated2/core.ts
+++ b/node_modules/react-native-reanimated/src/reanimated2/core.ts
@@ -383,9 +383,11 @@ if (!NativeReanimatedModule.useOnlyV1) {
         info: runOnJS(capturableConsole.info),
       };
       _setGlobalConsole(console);
-      global.performance = {
-        now: global._chronoNow,
-      };
+      if (global.performance == null) {
+         global.performance = {
+           now: global._chronoNow,
+         };
+       }
     })();
   }
 }

Or make change to this file: node_modules/react-native-reanimated/src/reanimated2/core.ts Line 386, remove this:

global.performance = {
     now: global._chronoNow,
 };

then add this:

if (global.performance == null) {
        global.performance = {
          now: global._chronoNow,
        };
      }

Hope that help, cheers!

28reactions
gorhomcommented, Dec 9, 2021

This is reanimated issue , fix will be released soon https://github.com/software-mansion/react-native-reanimated/commit/aef72c0875b559eecb7e10abaf00e49186d7ae55, for now I would advise to downgrade it to 2.2.4

Read more comments on GitHub >

github_iconTop Results From Across the Web

global.performance.now is not a function in react native ...
Unable to find any solution to this query. TypeError: global.performance.now is not a function at node_modules/expo/build/ ...
Read more >
TypeError: global.performance.now is not a function
1. make change to this file: node_modules/react-native-reanimated/src/reanimated2/core.ts Line 386, remove this: ; 2. ​ ; 3. global.performance = { ; 4. now: ...
Read more >
How to solve the issue that arise while using performance. ...
This is a very simple technique to measure the performance of a function. This time is not fixed, it may change every time...
Read more >
[Solved] TypeError: global.performance.now is not a function
How to Fix “TypeError: global.performance.now is not a function”? Ranjith Changed status to publish June 17, 2022 ...
Read more >
performance.now() - Web APIs - MDN Web Docs
The performance.now() method returns a DOMHighResTimeStamp, measured in milliseconds.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found