Skip to content
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

Error when using the "Unified (router-agnostic)" imports (Error: Cannot find module '/node_modules/next/navigation'…) #869

Open
tordans opened this issue Jan 22, 2025 · 3 comments
Labels
adapters/next/app Uses the Next.js app router adapters/next/pages Uses the Next.js pages router bug Something isn't working cannot-reproduce Either no reproduction provided, or cannot reproduce with a minimal setup

Comments

@tordans
Copy link
Contributor

tordans commented Jan 22, 2025

Context

What's your version of nuqs?

    "nuqs": "2.3.1",

What framework are you using?

  • ✅ Next.js (app router)
  • ✅ Next.js (pages router)

Which version of your framework are you using?

% npx next info

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.2.0: Fri Dec  6 18:40:14 PST 2024; root:xnu-11215.61.5~2/RELEASE_ARM64_T8103
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 22.9.0
  npm: 11.0.0
Relevant Packages:
  next: 14.2.23 // An outdated version detected (latest is 15.1.6), upgrade is highly recommended!
  eslint-config-next: 14.2.23
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.7.3
Next.js Config:
  output: N/A
 ⚠ An outdated version detected (latest is 15.1.6), upgrade is highly recommended!
   Please try the latest canary version (`npm install next@canary`) to confirm the issue still exists before creating a new issue.
   Read more - https://nextjs.org/docs/messages/opening-an-issue

Description

I migrated from "nuqs": "1.20.0" to "nuqs": "2.3.1" and followed the https://github.com/47ng/nuqs/blob/next/errors/NUQS-404.md docs to use import { NuqsAdapter } from 'nuqs/adapters/next' since we are using both, the pages and app folder.

Error: Cannot find module '/node_modules/next/navigation' imported from /node_modules/nuqs/dist/chunk-S37JZELB.js
Did you mean to import "next/navigation.js"?

I changed the imports to use the separate /app and /pages imports in the corresponding files and the error was gone.

Suggestion

Reevaluate the section https://nuqs.47ng.com/docs/adapters#nextjs-unified of the docs, it looks like that does not work as intended

@tordans tordans added the bug Something isn't working label Jan 22, 2025
@franky47 franky47 added adapters/next/app Uses the Next.js app router adapters/next/pages Uses the Next.js pages router labels Jan 22, 2025
@franky47
Copy link
Member

Thanks for the report, it looks like we need to be smarter and lazy load the correct adapter, as the pages router needs to import from next/navigation.js, and the app router from next/navigation, for some reason (see #368).

That or rework the pages router so that it doesn't use next/navigation at all (which was needed in v1 for compat, but now we can probably base it on top of next/router or something like that).

@franky47
Copy link
Member

franky47 commented Jan 28, 2025

I tried reproducing the error in the e2e test bench, but I don't see any errors (see PR #878).

I thought I had moduleResolution set to bundler in the tsconfig.json, which might have made a difference, but it's set to node, like in FixMyBerlin/atlas-app (which I assume is the app you were trying to update).

@tordans
Copy link
Contributor Author

tordans commented Jan 28, 2025

I thought I had moduleResolution set to bundler in the tsconfig.json, which might have made a difference, but it's set to node, like in FixMyBerlin/atlas-app (which I assume is the app you were trying to update).

In this case it was FixMyBerlin/trassenscout https://github.com/FixMyBerlin/trassenscout/blob/develop/tsconfig.json#L19 but that uses "moduleResolution": "node" as well.

@franky47 franky47 added the cannot-reproduce Either no reproduction provided, or cannot reproduce with a minimal setup label Jan 30, 2025
@franky47 franky47 removed this from the 🪵 Backlog milestone Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapters/next/app Uses the Next.js app router adapters/next/pages Uses the Next.js pages router bug Something isn't working cannot-reproduce Either no reproduction provided, or cannot reproduce with a minimal setup
Projects
None yet
Development

No branches or pull requests

2 participants