Make react router as peer dep instead of dependency#3001
Conversation
getting latest main
☁️ Nx Cloud ReportCI is running/has finished running commands for commit e98f51c. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 2 targetsSent with 💌 from NxCloud. |
|
start cannot be used without router, so a peer dependency is not expressing the correct relationship. |
|
May be we can expose all functions like createRouter from start then? By reexporting I mean. |
|
this seems like a workaround for some bundler issues. what's the proper solution here? |
SeanCassiere
left a comment
There was a problem hiding this comment.
Since we have it documented pretty much everywhere, that start is meant to be used with router, I think its fine to move it to peerDeps.
| @@ -134,7 +134,6 @@ | |||
| }, | |||
| "dependencies": { | |||
| "@tanstack/react-cross-context": "workspace:^", | |||
There was a problem hiding this comment.
It may be worth checking out, whether we are actually using the react-cross-context package and possibly remove it.
|
We faced this issue after nuking node_modules, removing package-lock and re-installing. I'm unsure on how tanstack packages follow semantic versioning. Should peer-dep only point to patch versions or minor versions also? To get around this issue we are currently overriding internal deps to stay within patch range. Example in pnpm: Just wanted to know if this PR will be enough? |
|
Does https://github.com/TanStack/router/pull/3318/files resolve this? |
|
is this still relevant? |
|
Hi @schiller-manuel, I was able to repro this issue with this example of authenticated routes using Clerk SDK - https://github.com/wobsoriano/tanstack-router-3001-repro
|
|
@wobsoriano and would this PR resolve the issue you encountered? |
Ignore my comment, looks like the PR is for Start. I just followed this from a different issue and commented here lol sry |
I keep seeing this issue in my app with clerk as well. I guess clerk's provider is using useRouter? My routes do, but none of my providers do. And the issue is that we can't make clerk's provider a child of the tanstack router provider, correct? So is the fix in clerk's code or tanstack? |


I came across this while debugging #3002
Some package managers/resolvers in certain cases, load different downstream packages for different imports.
For instance, in tanstack/start quick starter app, we import both
@tanstack/startand@tanstack/router.@tanstack/routeris imported in user application(See Getting Started) as well in@tanstack/start. In one place the resolver may resolve to a different module than in the other places.deno, for instance resolves
@tanstack/react-routerin user application to node_modules/.deno/@TanStack+react-router@1.87.12_1 and@tanstack/react-routerin@tanstack/startto node_modules/.deno/@TanStack+react-router@1.87.12This causes a null router value to be returned by useRouterState() and the following logs:
when the
<Outlet />code ultimately fetches context.In other words, the module that hung the context up was in
ssr.tsxviacreateStartHandler/StartServerwasnode_modules/.deno/@tanstack+react-router@1.87.12_1(because resolver resolved to that module)While, the code uses(and gets from resolver)
node_modules/.deno/@tanstack+react-router@1.87.12pnpm/deno/bun/yarn all three can resolve to different modules this way.
Related issues:
#3002 - deno issue
#2594 - refers to bun and pnpm
#2540 - refers to pnpm and yarn
#1692 - doesn't mention the package manager used, but seems to indicate a similar issue.
I have fixed only the react-router issue for now. But if people used
@tanstack/react-cross-contextdirectly in their code, then they will see this issue there as well.This means that potentially all the libraries in tanstack start/router should be appropriately set as peer dependencies instead of dependencies as a matter of best practice(because unlike a typical monorepo tanstack router packages should be independently usable as well). I will leave it for @tannerlinsley if/when he wants to do these changes, if he accepts this fix.
At the very least,
@tanstack/react-cross-contextshould be declared as peer dependency in@tanstack/routeras it is the container where we hang up the context(a singleton). Otherwise people will use it in their code and end up with two different contexts and will end up hitting their heads against the wall on why their context is empty in some part of the code while it is correctly obtained in other places(or worse they will have some 10 contexts).The potential packages can be seen by dependency tree where this practice should apply:
BTW this issue can show up in node as well if npm installs nested dependencies. I am not 100% sure on the module resolution logic of current npm but I believe at least older npm versions used to do this.