[Vite] Error: You must render this element inside a <Remix> element
when running dev server for the first time with default client entry
#7914
Labels
What version of Remix are you using?
0.0.0-nightly-3874120-20231103
Are all your remix dependencies & dev-dependencies using the same version?
Steps to Reproduce
(EDIT: It seems this is not limited to
pnpm
. It's reproducible withnpm
as well. See 2nd comment for details)(tldr; adding
@remix-run/react
tooptimizeDeps.include
might fix this issue.)I was trying to reproduce #7863 on CI, but it turns out this error always happens on clean installation.
Locally, I was seeing the same error several times, but after restarting the dev server, the error always went away (note that browser reload alone doesn't fix this).
Investigating further, I found that this is reproducible after
rm -rf node_modules && pnpm i && pnpm dev
.And I also found that same could be reproducible by effectively disabling dependency pre-bundling by
vite dev --force
(cf. https://vitejs.dev/guide/dep-pre-bundling.html).Here is a screenshot of the error with js code of default
client.entry.tsx
on the right top:Reveal screenshot
As partially seen from the screenshot, it seems that when default client entry inside
node_modules/@remix-run/dev
on pnpm is used,import { RemixBrowser } from "@remix-run/react"
is transformed to the following:However, comparing with user routes which also use
@rexmi-run/react
module, it looks like this:So, probably having a different import source is leading to some sort of "dual package hazard".
Note that, after the server restart (without
--force
), the error goes away and the same import looks like this:After seeing this, it came naturally to try adding
@remix-run/react
tooptimizedDeps.include
, and indeed this seems to fix the issue, i.e. no error even withvite dev --force
.You can see this error is fixed error on reproduction repo hi-ogawa/test-remix-vite-hmr-runtime#1 but now CI shows error from
@vitejs/plugin-react can't detect preamble
#7863.Right now, I don't fully understand the consequence of doing
optimizeDeps
, so I'm creating this issue first before trying to create a PR. I would appreciate if anyone has insight on this.Expected Behavior
No error for first
vite dev
Actual Behavior
Errro as described in "Steps to Reproduce"
The text was updated successfully, but these errors were encountered: