Description
I'm using React Router as a...
framework
Description
Hey folks 👋
I'm experiencing a specific issue in the latest version of react-router
(7.1.3, also affecting 7.1.2) after upgrading Vite to v6.
When I import xstate
in a project with this setup, I encounter the following error message:
Cannot find module '/Users/raulmelo/development/sandbox/react-router-xstate/vite6-react-router712/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]/node_modules/use-sync-external-store/shim/with-selector' imported from /Users/raulmelo/development/sandbox/react-router-xstate/vite6-react-router712/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]/node_modules/@xstate/react/dist/xstate-react.development.esm.js
Did you mean to import "use-sync-external-store/shim/with-selector.js"?
Initially, I thought it was an issue on the xstate
side (I haven't ruled out that they might need to fix the exports conditions), but I've narrowed down the problem's origin.
In the same setup, downgrading react-router
to v7.1.1
(still using v6) works without issues. I suspect something in the Vite plugin changed in v7.1.2 that started affecting the xstate
import.
Some thoughts before starting
- Node 18, 20, 22 produce the same results
- Using
npm
as package manager yields identical results - The app build works fine (
pnpm run build && pnpm run start
=> no problem) - Tested Vite 5 and 6 with vanilla React with and without
swc
=> all work without issue
Reproduction
The steps to reproduce are detailed in the repo's README (link below). Essentially, you need a Vite app using react router deps on 7.1.{2|3}
, Vite on 6.0.11
, and xstate (version doesn't matter, but I'm using the latest).
When running dev mode (pnpm run dev
), you'll encounter the problem.
CleanShot.2025-01-23.at.14.33.54.mp4
References
- Stackblitz
- Repo for cloning
- PR I recall that touched the Vite plugin
System Info
System:
OS: macOS 15.2
CPU: (8) arm64 Apple M1 Pro
Memory: 82.19 MB / 16.00 GB
Shell: 5.9 - /opt/homebrew/bin/zsh
Binaries:
Node: 22.13.1 - ~/.volta/tools/image/node/22.13.1/bin/node
Yarn: 1.22.0 - ~/.volta/tools/image/yarn/1.22.0/bin/yarn
npm: 10.9.2 - ~/.volta/tools/image/node/22.13.1/bin/npm
pnpm: 9.15.3 - ~/.volta/tools/image/pnpm/9.15.3/bin/pnpm
bun: 1.1.43 - ~/.bun/bin/bun
Browsers:
Brave Browser: 120.1.61.114
Chrome: 131.0.6778.265
Safari: 18.2
npmPackages:
@react-router/dev: 7.1.2 => 7.1.2
@react-router/node: 7.1.2 => 7.1.2
@react-router/serve: 7.1.2 => 7.1.2
@xstate/react: 5.0.2 => 5.0.2
react-router: 7.1.2 => 7.1.2
vite: 6.0.11 => 6.0.11
xstate: 5.19.2 => 5.19.2
Used Package Manager
pnpm
Expected Behavior
No problems with imports and dev server running
Actual Behavior
Got a full app crash due to the error described before