vitejs / vite-plugin-react-swc

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

React refresh preamble was not loaded #28

Closed ianschmitz closed 1 year ago

ianschmitz commented 1 year ago

Hi all! 👋

While migrating to Vite 4, i decided i would try this plugin as a replacement of @vitejs/plugin-react. When trying to load the page i get the following error:

image

Swapping back to plugin-react fixes the error. Let me know if there's any specific information i can provide to help debug!

ArnaudBarre commented 1 year ago

The second error is cause by the first one. That's difficult to know why it happened without a reproduction

ArnaudBarre commented 1 year ago

Closing as can't reproduce. Feel free to reopen if you have a repro.

enpitsuLin commented 1 year ago

this problem maybe cause by some other vite plugin in your project assigning a value to globalThis.__dirname same like this

https://github.com/vitejs/vite-plugin-react-swc/blob/786826fb81459d7e088703a048d5523f2841f7cd/src/index.ts#L16-L19

@ArnaudBarre It may not be necessary to check globalThis.__dirname just use dirname(fileURLToPath(import.meta.url)) directly?

ArnaudBarre commented 1 year ago

This is for cjs compatibility. I need to check but I think import.meta.url is not defined.

This is also what antfu uses: https://antfu.me/posts/isomorphic-dirname

This issue for me would be to override a variable with a very specific meaning in cjs. What's the goal of this?

quantuminformation commented 1 year ago

I just got this today, using a fresh vite repo

image

https://github.com/quantuminformation/chatgpt-youtube

mikeumus commented 3 months ago

@quantuminformation @ianschmitz @ArnaudBarre @enpitsuLin @yyx990803 did anyone ever find an solution to this. I'm facing it now and it's a booger. 👻

Had to put the Vite migration from Webpack on hold because of this 🥲

@quantuminformation, does your repo you linked (https://github.com/quantuminformation/chatgpt-youtube) reproduce the error for @ArnaudBarre to check out?

ArnaudBarre commented 3 months ago

@mikeumus There can be a lot of reason that causes this issue. Try to understand what file causes the issue and what is special about it and reproduce it starting from a new Vite + react-swc template

Also please don't ping Evan like that, we can't do anything if you just say I have this issue