react-native
react-native copied to clipboard
Tests are failing after upgrading react native from 0.69.6 to 0.71.0
Description
Hello! After the update I started getting the following errors:
TypeError: Cannot redefine property: performance
at Object.<anonymous> (node_modules/react-native/jest/setup.js:404:20)
TypeError: Cannot redefine property: window
at Object.<anonymous> (node_modules/react-native/jest/setup.js:405:15)
Everything works fine if I comment out the appropriate lines in file node_modules/react-native/jest/setup.js
:
...
global.__DEV__ = true;
// global.performance = {
// now: jest.fn(Date.now),
// };
global.regeneratorRuntime = jest.requireActual('regenerator-runtime/runtime');
// global.window = global;
global.requestAnimationFrame = function (callback) {
return setTimeout(callback, 0);
};
...
React Native Version
0.71.0
Output of npx react-native info
System:
OS: macOS 13.2.1
CPU: (8) x64 Apple M1
Memory: 16.64 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 19.7.0 - /usr/local/bin/node
Yarn: 1.22.17 - /usr/local/bin/yarn
npm: 9.5.0 - /usr/local/bin/npm
Watchman: 2023.02.27.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.12.0 - /Users/user/.rvm/gems/ruby-2.7.6/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1
Android SDK:
API Levels: 28, 29, 30, 31, 32, 33
Build Tools: 29.0.2, 29.0.3, 30.0.2, 30.0.3, 31.0.0, 32.0.0, 33.0.0
System Images: android-29 | Intel x86 Atom_64, android-31 | Google APIs ARM 64 v8a, android-32 | Google APIs ARM 64 v8a
Android NDK: Not Found
IDEs:
Android Studio: 2022.1 AI-221.6008.13.2211.9619390
Xcode: 14.2/14C18 - /usr/bin/xcodebuild
Languages:
Java: 11.0.11 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.2.0 => 18.2.0
react-native: 0.71.0 => 0.71.0
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
Steps to reproduce
Upgrade the RN version
Snack, code example, screenshot, or link to a repository
...
global.__DEV__ = true;
// global.performance = {
// now: jest.fn(Date.now),
// };
global.regeneratorRuntime = jest.requireActual('regenerator-runtime/runtime');
// global.window = global;
global.requestAnimationFrame = function (callback) {
return setTimeout(callback, 0);
};
...
:warning: | Newer Version of React Native is Available! |
---|---|
:information_source: | You are on a supported minor version, but it looks like there's a newer patch available. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases. |
I am also getting this error on a clean install of the Ignite boilerplate when running jest tests. My react-native version is 0.70.5
.
I rollback to the previous LTS node version (18) and the issue was resolved for me. Probably, the cause was in the latest node version (19). Looks like the jest setup file of RN is not compatible with that version
I rollback to the previous LTS node version (18) and the issue was resolved for me. Probably, the cause was in the latest node version (19). Looks like the jest setup file of RN is not compatible with that version
i can confirm
it does not work for me on node@19 as well
thanks @arthedza
That was it! Thank you for saving me banging my head against a wall for the next hour. :)
FYI, put something like this in your package.json
to prevent your fellow engineers from running into the same problem and to help document it:
"node": ">=16.0.0 <18.16.0"
Then once React Native supports Node 19+, make sure to update this to reflect the new "max" version of Node.
I've been able to replicate this with the current node 18 LTS version (18.16.0) switching back to 18.15.0 seems to work for now.
I have the same problem and also found locking down to 18.15 was the fix.
I've been able to replicate this with the current node 18 LTS version (18.16.0) switching back to 18.15.0 seems to work for now.
Do we have a fix for this issue. This just hit us after upgrading to 18.16.0
Had same issue had to lock our Node to 18.15.0, is a pr incoming for this?
I have this issue too. node --version = 18.16.0 React Native v0.71.10
TL;DR: Update Node.js to v18.17.0 or later
This was due to a Node.js bug in 18.16.x, fixed in Node.js 18.17.0 (and 19.9.0) by https://github.com/nodejs/node/commit/fb90b6b3fbec0da04be9c6560397a190a329dda0. See also https://github.com/nodejs/node/issues/47563.
With some help from @frankcalise I was able to repro and confirm the fix, so I'm closing the issue. If anyone still sees this problem on latest Node LTS, please open a new issue.