question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error with Router and prefetching

See original GitHub issue

What version of Next.js are you using?

12.0.2

What version of Node.js are you using?

14.18.1

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

Self deployment

Describe the Bug

Whenever I’m trying to navigate to a page which uses <Link> (which prefetches by default), router.ts file prints an error in the console

image

This error occurs in the _preflightRequest function in router.ts

On further investigation, I found that, this.pageLoader.getMiddlewareList(); returns a Set (of size 0, since I have no middlewares). And it then tries to call .some on the Set.

Expected Behavior

The navigation should happen normally

To Reproduce

Upgrade any NextJS project from v11 to v12, and this issue occurs.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
bielcapanemacommented, Nov 18, 2021

Same here, it only occurs in a build deployed to production environment. Running locally, even with a production build, it works fine 😕

2reactions
prarabdhbcommented, Nov 8, 2021

Any update on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

router.prefetch is not a function , Unable to check submit ...
Whenever I need to use "next/router" I always call useRouter like this and assign it to a variable: import { useRouter } from...
Read more >
Route prefetching in Next.js - web.dev
In this post you'll learn how routing in Next.js works, how it's optimized for speed, and how to customize it to best fit...
Read more >
Prefetching - Redux Toolkit
Prefetching. The goal of prefetching is to make data fetch before the user navigates to a page or attempts to load some known...
Read more >
Pre-fetching lazy loaded modules produces an error while ...
I noticed an error which occurred as a result of it. Whenever i tried navigating to a different route before the notify info...
Read more >
next/link | Next.js
Before moving forward, we recommend you to read Routing Introduction first. ... When prefetch is set to false , prefetching will still occur...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found