-
-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Monorepo setup - Error: [nuqs] nuqs requires an adapter to work with your framework. #798
Comments
As an update, got this resolved by manually editing the pnpm-lock and removing the first entry under snapshots in the post above. Again not sure if this is nuqs, pnpm or something on our end. FWIW uninstalling did remove every nuqs reference in the lock, adding it added both of those automatically. |
Are you importing the adapter and using the hooks that cause the error in different packages by any chance? I think this is what would cause the issue: different instances of the module being loaded in memory by different parts of your monorepo setup, causing the React Context reference to differ, and making nuqs hooks unaware of the adapter/provider which is under a different reference. Since manually editing the lockfile isn't very robust, have you tried using pnpm overrides yet? It feels like it could be a good candidate for pinning the same nuqs module reference across all consuming packages. |
This is indeed what I'm doing, and that makes a lot of sense. I'll look into that! Thanks! |
@janglad have you had any luck in making it work? |
I actually haven't sadly, using the overwrites you mentioned does not fix the issue when using a specifier like "2.2.3" (that version was shared between the versions either way), and using the exact one used in the lock doesn't work either. It is working again right now due to the manual lock edit but yeah indeed just very brittle. I guess another solution would he creating a single package that just has Nuqs, and using it across the repo from there? |
Thanks for the feedback. Would you be able to create a minimal reproduction repo? I'm pretty sure there's got to be a pnpm config that causes/explains this behaviour, as the root of the issue is in the lock resolution, it should not require a userland fix. If all else fails, could be a bug to escalate to PNPM. |
We had the same issue with our monorepo when importing components using nuqs from a turborepo package. The error went away when we included both react and nextjs as dependencies in the turborepo package. Not sure if this is the best way to solve it, but seemed to do the trick for us without fiddling with the pnpm-lock file. |
The package in question already has deps on both of those so sadly doesn't seem like a reliable way to solve it |
also a little bit hacky, but you can try to re-export everything from nuqs from your shared package and then only import from that file, so there is only one dep on nuqs in the shared package |
in my case sometimes it appears it doesn't. |
In case anyone else runs into this with turborepo, I ended up installing nuqs at the root of the repo so the same dependency is referenced in every package. Not ideal, but it worked for me. |
any reason we are not using this adapter? or it just came out? https://nuqs.47ng.com/docs/adapters . this worked for me but am yet to test its implications. |
The root cause of this issue is described in the React docs in the useContext troubleshooting section:
The If someone is feeling adventurous, here's the steps to test if the context reference had already been created:
if (process.env.NODE_ENV === 'development') {
if (typeof window !== 'undefined') {
if (
window.__NuqsAdapterContext !== undefined &&
window.__NuqsAdapterContext !== context
) {
console.error('[nuqs] Adapter context was already created')
}
window.__NuqsAdapterContext = context
}
}
|
I added this in a preview PR, to make it a bit user-friendlier. Steps are now:
It will log an error if multiple context references are loaded. |
Context
What's your version of
nuqs
?2.2.3
What framework are you using?
Next JS
Which version of your framework are you using?
Description
We have a turbo pnpm monorepo with next js. Nuqs has been acting up for a bit, erroring out and saying that the adapter isn't installed. This is however the case (and the adapter gets resolved fine). In the past this was fixed by uninstalling nuqs from the pacakges that used it and adding it again, however this now also isn't working. Below is relevant information about nuqs in the pnpm-lock
The thing that jumps out to me is the mismatch in the long string of seemingly next specific identifiers (babel/core...). I'm not sure if this maters, and if it does if this is an issue on the Nuqs side or on the pnpm side (or ours!).
The text was updated successfully, but these errors were encountered: