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

Cypress implicitly expects react-dom to be installed during component testing setup #22371

Closed
rluisnpt1 opened this issue Jun 17, 2022 · 4 comments · Fixed by #22572
Closed
Assignees
Labels
CT Issue related to component testing type: bug

Comments

@rluisnpt1
Copy link

rluisnpt1 commented Jun 17, 2022

Current behavior

Cypress 10.1.0 - Components setup using web interface does not work when select React and vite.

[15940:0617/071413.082:ERROR:gpu_init.cc(446)] Passthrough is not supported, GL is disabled, ANGLE is                                                                               d, ANGLE is 
X [ERROR] Could not resolve "react-dom"

    node_modules/cypress/react/dist/cypress-react.esm-bundler.js:9:26:
      9 Γöé import * as ReactDOM from 'react-dom';
        Γò╡                           ~~~~~~~~~~~
  You can mark the path "react-dom" as external to exclude it from the bundle, which will 
remove this error.

7:26:45 AM [vite] error while updating dependencies:
TypeError: Cannot read properties of undefined (reading 'outputs')
    at runOptimizeDeps (C:\Users\nlrdn\GravitySource\rluisn-devtest\Cypress-TestFramework\node_modules\vite\dist\node\chunks\dep-8f5c9290.js:39993:49)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runOptimizer (C:\Users\nlrdn\GravitySource\rluisn-devtest\Cypress-TestFramework\node_modules\vite\dist\node\chunks\dep-8f5c9290.js:50498:38)

Desired behavior

Cypress does not crashes when using React and vite Into DevServer

Test code to reproduce

yarn add cypress --dev
npx cypress open

3- Then in the first page select components *beta
4- When the combo box appear, select React and Vite as bundle combination.
5- Then execute the command in the terminal yarn add -D vite react
6- And create the vite.config.ts

//vite.config.ts
import { defineConfig, loadEnv } from 'vite'

// https://vitejs.dev/config/

module.exports = defineConfig(({ command, mode }) => {

    // Load env file based on `mode` in the current working directory.
    // Set the third parameter to '' to load all env regardless of the `VITE_` prefix.
    const env = loadEnv(mode, process.cwd(), '')

    if (command === 'serve') {
        return {
            // dev specific config
            define: {
                __APP_ENV__: env.APP_ENV
            }
        }
    } else {
        // command === 'build'
        return {
            // build specific config
            define: {
                __APP_ENV__: env.APP_ENV
            },
            build: {
                lib: {
                    entry: 'src/index.ts',
                    formats: ['es']
                },
                rollupOptions: {
                    // make sure to externalize deps that shouldn't be bundled
                    // into your library
                    external: /^lit/,
                    output: {
                        // Provide global variables to use in the UMD build
                        // for externalized deps
                        globals: {
                            lit: 'lit'
                        }
                    }
                }
            }
        }
    }
})

Cypress Version

10.1.0

Other

No response

@lmiller1990
Copy link
Contributor

Hi! I think I see the problem - we should be adding react-dom as a dependency, not just react - you need them both. You could try adding react-dom.

As an aside, I'm working on React 18 support (with the new createRoot mounting API here), which will be done soon. In the meantime, I'd recommend doing npm install react@17 react-dom@17

Also - in your vite.config.ts, you might want export default instead of module.exports. See here for a configured, working example (check vite.config.ts - you need the @vitejs/react plugin).

Can you try npm install react@17 react-dom@17?

@emilyrohrbough emilyrohrbough added the stage: awaiting response Potential fix was proposed; awaiting response label Jun 22, 2022
@cypress-bot cypress-bot bot added stage: routed to ct and removed stage: awaiting response Potential fix was proposed; awaiting response labels Jun 22, 2022
@mjhenkes mjhenkes added stage: awaiting response Potential fix was proposed; awaiting response CT Issue related to component testing type: bug and removed stage: routed to ct labels Jun 22, 2022
@lmiller1990 lmiller1990 assigned astone123 and unassigned lmiller1990 Jun 23, 2022
@lmiller1990
Copy link
Contributor

I talked to @astone123 and have assigned this one to him. We will fix it. In the meantime, installing react and react-dom in your project should let you progress (most react projects should have these already).

@cypress-bot cypress-bot bot added stage: open and removed stage: awaiting response Potential fix was proposed; awaiting response stage: open labels Jun 23, 2022
@astone123 astone123 changed the title Cypress 10.1.0 - Component setup - React, Vite Error Cypress implicitly expects react-dom to be installed during component testing setup Jun 28, 2022
@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review stage: review and removed stage: in progress stage: needs review The PR code is done & tested, needs review labels Jun 28, 2022
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jun 29, 2022

The code for this is done in cypress-io/cypress#22572, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jul 19, 2022

Released in 10.3.1.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v10.3.1, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Jul 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CT Issue related to component testing type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants