Closed myktra closed 1 year ago
Added link to repo reproducing the issue above.
The new file writer will land in @crxjs/vite-plugin
v2.0. It's in beta right now, you can test it using:
npm i @crxjs/vite-plugin@beta -D
Now having success with the plugin v2 beta and Vite v3! Thanks!
Build tool
Vite
Where do you see the problem?
Describe the bug
When using yarn (but not npm!), the use of the @crxjs/vite-plugin at versions 1.0.13 and higher causes content scripts to break (but not popups) when installing/running the extension via
vite dev
. The specific error that will appear in the console if ANY React component is injected into a content script:This blocks the rendering of the components in the content script (you'll see nothing).
Again, this does NOT happen for React components injected into a popup (i.e. not a content script) - those work fine with
vite dev
. And a regularvite build
works fine as well.After digging in a little, I noticed that with yarn, when using @crxjs/vite-plugin 1.0.13 and higher, the dependency resolver winds up installing a copy of the newer v2 line of @vitejs/plugin-react, which seems to be a cause of the conflict.
By pinning @crxjs/vite-plugin to 1.0.12, the following resolution in yarn.lock occurs:
...and HMR works again with
vite dev
.So essentially the ask here is to update the documentation that if you ARE using yarn, which is quite common, that you pin the plugin to 1.0.12. Content scripts will not work with 1.0.13 or higher.
As a hypothetical workaround it may also be possible to use an override in package.json to ensure 1.3.2 of @vitejs/plugin-react is used in the project.
Hopefully all of this goes away once we can use vite@3 and @vitejs/plugin-react@2, which from what I have read requires a rewrite of the file writer.
Reproduction
Here's a repo
The repo above shows a working extension with yarn by pinning @crxjs/vite-plugin to version 1.0.12. Update
package.json
to pin to 1.0.13 or higher and you'll see that it breaks as described above.Logs
No response
System Info
Severity
annoyance