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

Tests are failing after upgrading react native from 0.69.6 to 0.71.0 #36440

Closed
arthedza opened this issue Mar 10, 2023 · 11 comments
Closed

Tests are failing after upgrading react native from 0.69.6 to 0.71.0 #36440

arthedza opened this issue Mar 10, 2023 · 11 comments

Comments

@arthedza
Copy link

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);
};
...
@github-actions
Copy link

⚠️ Newer Version of React Native is Available!
ℹ️ 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.

@loganfuller
Copy link

loganfuller commented Mar 13, 2023

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.

@arthedza
Copy link
Author

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

@seelts
Copy link

seelts commented Mar 22, 2023

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

@joshuapinter
Copy link
Contributor

joshuapinter commented Mar 29, 2023

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.

@Donald47
Copy link

Donald47 commented Apr 18, 2023

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.

IvanGodinez21 added a commit to BrightCoders-Institute/BCDIC22-RN-proyecto-final-team3 that referenced this issue Apr 22, 2023
Fixed:
- Theme changes to light mode when registering
- CWInfo aligned
- Following screen's loading was infinity when follows were at 0

Notes:
- Node 18.16.0 (which is 18.x at the commit date) version fails to generate coverage when using Jest in the GitHub Action. Using 18.15.0 version for the moment until another update release, see: facebook/react-native#36440 (comment)
@timhooker
Copy link

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.

@utsavkapoor
Copy link

Do we have a fix for this issue. This just hit us after upgrading to 18.16.0

@GroovyLLR
Copy link

Had same issue had to lock our Node to 18.15.0, is a pr incoming for this?

@nzcodarnoc
Copy link

nzcodarnoc commented Jun 11, 2023

I have this issue too.
node --version = 18.16.0
React Native v0.71.10

@robhogan
Copy link
Contributor

robhogan commented Dec 1, 2023

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 nodejs/node@fb90b6b. See also nodejs/node#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants