vitejs / vite-plugin-react-swc

Speed up your Vite dev server with SWC
MIT License
831 stars 54 forks source link

Uncaught ReferenceError: _<variable_name> is not defined #77

Closed NazmusSayad closed 1 year ago

NazmusSayad commented 1 year ago

Describe the bug

I am using "@vitejs/plugin-react-swc". I used the useRef hook and saved its value inside a variable named "imageContainer".

Then this happens: Uncaught ReferenceError: _imageContainer is not defined

There isn't a single variable named "_imageContainer" in my whole project. Then I tried the "@vitejs/plugin-react" and it's perfectly working. I have also tried my versions of "@vitejs/plugin-react-swc" and "vite" all of them have the same issue.

But I have an old version where swc was working. Working repo: https://github.com/NazmusSayad/messagen-client/tree/swc-working Not working repo: https://github.com/NazmusSayad/messagen-client/tree/swc-error

Reproduction

https://github.com/NazmusSayad/messagen-client/tree/swc-error

Steps to reproduce

  1. yarn

  2. yarn dev

  3. http://localhost:3000/login

  4. You need an account now, username: "NazmusSayad", password: "hello world!"

  5. http://localhost:3000/chat/6416e099b4652ab4149e9e42

System Info

System:
    OS: Linux 5.4 Debian GNU/Linux 10 (buster) 10 (buster)
    CPU: (2) x64 Intel(R) Xeon(R) Platinum 8272CL CPU @ 2.60GHz
    Memory: 1.54 GB / 3.84 GB
    Container: Yes
    Shell: 5.0.3 - /bin/bash
  Binaries:
    Node: 18.15.0 - /usr/local/share/nvm/versions/node/v18.15.0/bin/node
    Yarn: 1.22.19 - /usr/local/share/nvm/versions/node/v18.15.0/bin/yarn
    npm: 9.6.2 - /usr/local/share/nvm/versions/node/v18.15.0/bin/npm
  npmPackages:
    @vitejs/plugin-react: ^3.0.0 => 3.0.0 
    vite: ^4.2.0 => 4.2.0

Used Package Manager

yarn

Logs

No response

Validations

ArnaudBarre commented 1 year ago

hello,

This will take time to identify the root cause. I see that you're bumping a lot of dependencies together, can you reproduce when changing one the react-swc plugin?

NazmusSayad commented 1 year ago

Yeah, I tried. In the working version just after changing the swc package I am facing this error

NazmusSayad commented 1 year ago

Clone the working branch then run "y add -D @vitejs/plugin-react-swc". You will face the same error

ArnaudBarre commented 1 year ago

Just tried the repro, switch to swc, restart and I'm able to load the home page. What's your node version & os?

NazmusSayad commented 1 year ago

The homepage is working. Follow the "Steps to reproduce". You can find the issue here: "http://localhost:3000/chat/6416e099b4652ab4149e9e42"

ArnaudBarre commented 1 year ago

Sorry didn't forgot to look at the steps. This is broken since swc v1.3.40.

You can avoid this by pinning the version:

  "resolutions": {
    "@swc/core": "1.3.39"
  },
ArnaudBarre commented 1 year ago

Oh actually this is also working with 1.3.44. Found the PR: https://github.com/swc-project/swc/pull/7171

NazmusSayad commented 1 year ago

I see... Ok thanks