🐛 BUG:Server restart fails with 'Miniflare not defined' with the react-router template
Which template does this pertain to?
react-router
What versions are you using?
wrangler 4.30.0, @cloudflare/vite-plugin 1.11.5
What operating system and version are you using?
Windows 10
Please provide a link to a minimal reproduction (optional)
No response
Describe the Bug
-
create a new repo with template
pnpm create cloudflare@latest my-project --framework=remix. I used pnpm for packages and enabled git -
npm run devand open the webpage on http://localhost:5173 -> this works -
save the vite.config.ts file to trigger a server restart -> The page fails to load. The error "Internal server error: Miniflare not defined" is logged
1:07:20 PM [vite] vite.config.ts changed, restarting server...
1:07:20 PM [vite] server restarted.
1:07:21 PM [vite] Internal server error: Miniflare not defined
at file:///<redacted>/node_modules/.pnpm/@[email protected]_6a88507fdcd1282573f3b2a56b1fd08f/node_modules/@cloudflare/vite-plugin/dist/index.js:16408:15
at file:///<redacted>/node_modules/.pnpm/@[email protected]_6a88507fdcd1282573f3b2a56b1fd08f/node_modules/@cloudflare/vite-plugin/dist/index.js:13466:28
at call (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19166:7)
at next (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19110:5)
at viteServeStaticMiddleware (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:35429:14)
at call (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19166:7)
at next (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19110:5)
at viteServeRawFsMiddleware (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:35492:7)
at call (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19166:7)
at next (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19110:5)
at viteTransformMiddleware (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:37158:14)
at call (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19166:7)
at next (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19110:5)
at viteServePublicMiddleware (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:35410:14)
at call (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19166:7)
at next (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19110:5)
at viteHMRPingMiddleware (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:38685:7)
at call (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19166:7)
at next (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19110:5)
at next (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19088:14)
at viteCachedTransformMiddleware (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:37148:5)
at call (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19166:7)
at next (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19110:5)
at viteHostCheckMiddleware (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:32240:12)
at call (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19166:7)
at next (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19110:5)
at cors (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19638:7)
at file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19674:17
at originCallback (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19664:15)
at file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19669:13
at optionsCallback (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19649:9)
at corsMiddleware (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19654:7)
at call (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19166:7)
at next (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19110:5)
at viteRejectInvalidRequestMiddleware (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:38321:12)
at call (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19166:7)
at next (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19110:5)
at <redacted>\node_modules\.pnpm\@[email protected]_@ty_62f5643a7f0fdeb25eba91175062cf60\node_modules\@react-router\dev\dist\vite.js:3380:15
at call (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19166:7)
at next (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19110:5)
at next (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19088:14)
at Function.handle (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:19113:3)
at Server.app (file:///<redacted>/node_modules/.pnpm/[email protected]_@[email protected]_be77f164addcd21b9b7e1848bff4e63f/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:18978:37)
at Server.emit (node:events:524:28)
at Server.emit (node:domain:489:12)
at parserOnIncoming (node:_http_server:1153:12)
at HTTPParser.parserOnHeadersComplete (node:_http_common:117:17)
my package.json:
{
"name": "my-project",
"private": true,
"type": "module",
"scripts": {
"build": "react-router build",
"cf-typegen": "wrangler types",
"deploy": "pnpm run build && wrangler deploy",
"dev": "react-router dev",
"postinstall": "npm run cf-typegen",
"preview": "pnpm run build && vite preview",
"typecheck": "npm run cf-typegen && react-router typegen && tsc -b"
},
"dependencies": {
"isbot": "^5.1.27",
"react": "^19.1.0",
"react-dom": "^19.1.0",
"react-router": "^7.7.1"
},
"devDependencies": {
"@cloudflare/vite-plugin": "^1.0.12",
"@react-router/dev": "^7.7.1",
"@tailwindcss/vite": "^4.1.4",
"@types/node": "^20",
"@types/react": "^19.1.2",
"@types/react-dom": "^19.1.2",
"tailwindcss": "^4.1.4",
"typescript": "^5.8.3",
"vite": "^6.3.3",
"vite-tsconfig-paths": "^5.1.4",
"wrangler": "^4.30.0"
}
}
I've also tried updating all the packages to the latest version, but that didn't change anything
Please provide any relevant error logs
No response
Hi! Thanks for filing this issue. I've tried to reproduce it, but unfortunately am unable to. Editing the vite.config.ts file while the dev server is running does not crash for me.
7:06:58 AM [vite] vite.config.ts changed, restarting server...
7:06:59 AM [vite] server restarted.
Couple of questions to help us diagnose further:
-
Which version of pnpm are you running? (I'm using 10.14.0.)
-
Are you inside a monorepo (do you have a higher
package.jsonwhich might be messing with module resolution)? -
Once you do edit and save
vite.config.ts, if you restart the dev server manually, do you continue to see an error? Or is this only an issue for the automatic restarts?
Thanks again! Let us know about these points and we'll dig in further!
Hi @GregBrimble
-
pnpm --versionprints 10.13.1 -
I'm not in a monorepo or similar setup where a higher package.json is present
-
I don't get the error on manual restart, this is only an issue for automatic restarts.
I'd like to mention 2 more things in case they are useful:
- this same error also reproduces when saving other files that trigger a server restart, such as .env or tsconfig.json
- I'm on Windows, not linux. Perhaps the file-system watching timings are different than on other platforms? just a guess though. I wasn't able to get pnpm to work at all on linux
Okay, thanks, that's helpful! I'm going to bounce you over to another team who own the Vite integration and might have a bit more context than me for how to help debug further. It doesn't sound like this is specific to this template, if just editing any file (which triggers an automatic restart) is enough to cause this.
Hie. Is there an update on this? I'm trying to port an existing react router app to be deployable on workers but I'm currently blocked by this issue.
This is what I found further debugging, hope this helps fixing this.
This happens when vite server is restarted. It triggers this assert which leads to an error on the dev server. It might be caused by the middleware still hanging around while it's restarted and it's still triggering createRequestHandler which leads to miniflare not defined.
https://github.com/cloudflare/workers-sdk/blob/6619feb7a169623fb19e98aa2cbd66f30b7cbfb3/packages/vite-plugin-cloudflare/src/index.ts#L559-L578
> react-router dev --port 3000
Using vars defined in .env
@CLOUDFLARE:VITE-PLUGIN 93536: Creating new Miniflare instance
@CLOUDFLARE:VITE-PLUGIN 93536: Initializing the Vite module runners
@CLOUDFLARE:VITE-PLUGIN 93536: Initializing worker: purps-frontend
➜ Local: http://localhost:3000/
➜ Network: use --host to expose
➜ Debug: http://localhost:3000/__debug
➜ press h + enter to show help
1:07:57 PM [vite] vite.config.ts changed, restarting server...
@CLOUDFLARE:VITE-PLUGIN 93536: From server.restart(): Restarting server...
Using vars defined in .env
@CLOUDFLARE:VITE-PLUGIN 93536: Updating the existing Miniflare instance
@CLOUDFLARE:VITE-PLUGIN 93536: Miniflare is ready
@CLOUDFLARE:VITE-PLUGIN 93536: Initializing the Vite module runners
@CLOUDFLARE:VITE-PLUGIN 93536: Initializing worker: purps-frontend
@CLOUDFLARE:VITE-PLUGIN 93536: buildEnd: restarted
@CLOUDFLARE:VITE-PLUGIN 93536: buildEnd: disposing
@CLOUDFLARE:VITE-PLUGIN 93536: buildEnd: disposing Miniflare instance
1:07:57 PM [vite] server restarted.
@CLOUDFLARE:VITE-PLUGIN 93536: From server.restart(): Restarted server...
1:07:58 PM [vite] Internal server error: Miniflare not defined
Also happens for me on a mac, e.g. everytime I update wrangler.jsonc with a running server.
Same here (MacOS), within 3-5 structural updates (not just wrangler, imports/removing components/etc), the error appears and I have to restart the dev server
Same here, Ubuntu 22.04 running on WSL2. Running on Bun 1.2.21, node 22.20 installed.
Happens in various repos, all based around the react-router template.