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 component test produces "@vitejs/plugin-react can't detect preamble. Something is wrong" #9362

Closed
7 tasks done
froko opened this issue Jul 25, 2022 · 5 comments
Closed
7 tasks done

Comments

@froko
Copy link

froko commented Jul 25, 2022

Describe the bug

I maintain an app skeleton with Vite, React, and optional Cypress support. Since the upgrade to Vite3, I get the "@vitejs/plugin-react can't detect preamble. Something is wrong" failure message when running the Cypress component tests. It used to work fine with Vite2.

Screenshot 2022-07-25 at 13 58 58

Reproduction

https://github.com/froko/vite-ts-react/tree/cypress-vite-3

System Info

System:
    OS: macOS 12.4
    CPU: (4) x64 Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz
    Memory: 281.67 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.15.0 - /usr/local/bin/node
    npm: 8.5.5 - /usr/local/bin/npm
  Browsers:
    Brave Browser: 103.1.41.96
    Chrome: 78.0.3904.108
    Edge: 103.0.1264.71
    Safari: 15.5
  npmPackages:
    @vitejs/plugin-react: ^2.0.0 => 2.0.0 
    cypress: ^10.3.1 => 10.3.1 
    vite: ^3.0.2 => 3.0.2

Used Package Manager

npm

Logs

No response

Validations

@sapphi-red
Copy link
Member

Cypress does not support Vite 3 yet: cypress-io/cypress#22784

Closing for the reason above but feel free to create a new issue if it turns out that this is a bug in Vite.

@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Jul 25, 2022
@lmiller1990
Copy link

lmiller1990 commented Jul 25, 2022

I found the problem, we will support soon (maybe next release, that's usually biweekly).

FYI PR: cypress-io/cypress#22915

FYI this was the problem, Vite 3.x had some breaking changes around transformIndexHtml I think. Here's how I fixed it, at least in our Vite dev server integration:

https://github.com/cypress-io/cypress/pull/22915/files#diff-5b3ea0fa70e7e1e8a968123451e3b68ad11cde664c56ef07e4ccdd02769887e5R56-R94

For now, you might need to stay on Vite 2. This should be released very soon in Cypress 👍

@sapphi-red
Copy link
Member

@bzbetty
Copy link

bzbetty commented Jul 31, 2022

Found another work around:

  • in cypress.config.ts
  • override the devServer/viteConfig/plugins/react() config to disable faster refresh

essentially:

export default defineConfig({
    component: {
        devServer: {          
            viteConfig: {
                plugins: [
                    react({
                        include: '**/*.disabled'
                    }),

@lmiller1990
Copy link

Just wait for the next Cypress patch release - cypress-io/cypress#22915 is merged, which fixes the issue.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants