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.

Cypress Testing fails to build on React version 18

See original GitHub issue

Current behavior

Hey guys, we’ve encountered an error that is disrupting our build pipeline 😦 (oh no!)

Currently Cypress only allows react 16 in the package.json. These days some other packages require at least React 18, making this Cypress tester incompatible with those packages. When installing this with pnpm, or another package manager, warnings about incompatible react versions cause builds to fail, disrupting the build pipeline.

PNPM:

 WARN  Issues with peer dependencies found
.
└─┬ @cypress/react
  ├── ✕ unmet peer @types/react@"^16.9.16 || ^17.0.0": found 18.0.8
  ├── ✕ unmet peer react@"^=16.x || ^=17.x": found 18.1.0
  └── ✕ unmet peer react-dom@"^=16.x || ^=17.x": found 18.1.0

We were able to get past this by ignoring all warnings, and errors, but obviously this is not something we want to do.

Turns out, from our testing it a bit, Cypress seems to work just fine with React 18 (after ignoring the errors and just running everything manually). But we didn’t have time to test it extensively yet.

From doing some research it seems like the biggest bottleneck comes from the Enzyme package being limited at React 16. And this package is not getting many updates these days.

Desired behavior

We should be able to run Cypress on react 18.

We should look into migrating away from Enzyme, if possible. Potentially to rely on React Testing Library.

Test code to reproduce

Following this official getting-started guide produces the failure state.

https://www.cypress.io/blog/2021/04/06/cypress-component-testing-react/

Using pnpm, and installing the missing peer dependencies, you will reach a request saying

 WARN  Issues with peer dependencies found
.
└─┬ @cypress/react
  ├── ✕ unmet peer @types/react@"^16.9.16 || ^17.0.0": found 18.0.8
  ├── ✕ unmet peer react@"^=16.x || ^=17.x": found 18.1.0
  └── ✕ unmet peer react-dom@"^=16.x || ^=17.x": found 18.1.0

If you downgrade react to react 16, then other packages start failing. It becomes difficult to find a golden package configuration that meets everything.

Cypress Version

Cypress package version: 9.6.0

Other

Cypress package version: 9.6.0 Cypress binary version: 9.6.0 Electron version: 15.5.1 Bundled Node version: 16.5.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:6
  • Comments:20 (12 by maintainers)

github_iconTop GitHub Comments

5reactions
lmiller1990commented, Jul 19, 2022

Anyone following this: still working on a production grade, bullet proof solution, hoping to have it in the next release. We may end up going with cypress/react18 etc, for reliability and scalability - moving forward, we’d then have cypress/react19 for v19, etc.

3reactions
lmiller1990commented, Jul 27, 2022

It’s merged https://github.com/cypress-io/cypress/pull/22876. It will be in the next release, 10.4.0. We release on a biweekly cadence, so it should be soon. You will need to change your import to cypress/react18 to get the React 18 adapter.

Most likely cypress/react will default to React 18 in the next major Cypress release, Cypress 11, which would be a breaking change, which is why it’ll wait for the next major.

So, for now, it’s an opt in feature.

Read more comments on GitHub >

github_iconTop Results From Across the Web

@cypress/react - npm
Test React components using Cypress. Latest version: 7.0.2, last published: 24 days ago. Start using @cypress/react in your project by ...
Read more >
React Quickstart - Cypress Documentation
This tutorial will walk you through creating a React app and using Cypress Component Testing to test it. We assume you are already...
Read more >
Testing React Apps In 2022 With Cypress: An In-Depth Guide ...
js app that we'll use as an existing codebase to cover with tests on this page. It's an error tracking tool similar to...
Read more >
When visiting cypress.io, I get Minified React error #418
I can now run the tests without the exception. Thank you! – webghost. Nov 20 at 18:35. Add a comment ...
Read more >
Invalid Hook Call Warning - React
You might be using a version of react-dom (< 16.8.0) or react-native (< 0.59) that doesn't yet support Hooks. You can run npm...
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