router: Error after upgrading to v1.121.0 - `Invariant failed: Could not find a nearest match!`
Which project does this relate to?
Start
Describe the bug
After upgrading all the packages and going through the migration guide, when I try to start up the app I get this error:
[vite] connected.
Error in renderToPipeableStream: Error: Invariant failed: Could not find a nearest match!
at invariant (file:///Users/josippapez/Desktop/brisk-fit-web-static/node_modules/tiny-invariant/dist/esm/tiny-invariant.js:12:11)
at Object.select (/Users/josippapez/Desktop/brisk-fit-web-static/node_modules/@tanstack/react-router/src/useMatch.tsx:104:7)
at <anonymous> (/Users/josippapez/Desktop/brisk-fit-web-static/node_modules/@tanstack/react-router/src/useRouterState.tsx:55:19)
at memoizedSelector (/Users/josippapez/Desktop/brisk-fit-web-static/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js:47:30)
at /Users/josippapez/Desktop/brisk-fit-web-static/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js:76:26
at Object.useSyncExternalStore (/Users/josippapez/Desktop/brisk-fit-web-static/node_modules/react-dom/cjs/react-dom-server.node.development.js:9126:18)
at process.env.NODE_ENV.exports.useSyncExternalStore (/Users/josippapez/Desktop/brisk-fit-web-static/node_modules/react/cjs/react.development.js:1228:34)
at process.env.NODE_ENV.exports.useSyncExternalStoreWithSelector (/Users/josippapez/Desktop/brisk-fit-web-static/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js:82:19)
at useStore (/Users/josippapez/Desktop/brisk-fit-web-static/node_modules/@tanstack/react-store/src/index.ts:23:17)
at useRouterState (/Users/josippapez/Desktop/brisk-fit-web-static/node_modules/@tanstack/react-router/src/useRouterState.tsx:45:10) { componentStack: [Getter] }
Your Example Website or App
none
Steps to Reproduce the Bug or Issue
- Upgrade to v1.121.0
- Go through the migration guide
- Try to start the app
Expected behavior
It should start as it did before the migration
Screenshots or Videos
No response
Platform
- OS: macOS
- Browser: Firefox (Zen Browser)
- Version: latest zen browser
Additional context
No response
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 3
- Comments: 15 (5 by maintainers)
same error, trying to upgrade from v1.117 to 1.127.3.
After further investigation it is related to a context that I added to Router’s
InnerWrapbecause the context needs useNavigate hook.The fix is to remove it from
createRouter/InnerWrapand add it to my root Route.Instead of
I’m moving it to:
This is
@tanstack/react-start-client. See my comment here https://github.com/TanStack/router/issues/4380#issuecomment-2963391902