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.

Vercel deployment issue 404: NOT_FOUND when using middleware on dynamic routes

See original GitHub issue

Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Home Single Language
    Binaries:
      Node: 16.13.2
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 12.1.5-canary.1
      react: 18.0.0
      react-dom: 18.0.0

What browser are you using? (if relevant)

Microsoft Edge

How are you deploying your application? (if relevant)

Vercel

Describe the Bug

I am deploying my apps to Vercel. but got a 404 not found page when I have _middleware.ts on dynamic routes and when I’m visiting the dynamic routes.

image

It works fine in my local

My middleware just return the NextResponse,next() like this

import { NextResponse } from "next/server";

const middleware = () => {
  return NextResponse.next();
};

export default middleware;

Expected Behavior

  • Page can be visited when deployed to Vercel without a 404 issue

To Reproduce

I created a small repository to reproduce

https://github.com/bryantobing12/try-next-middleware

To test. when visiting /test it’s returning 404 not found when deployed to vercel. Only happening in dynamic routes

i have this route /[customerSlug] https://try-next-middleware.vercel.app/test

It works fine When visiting static page

https://try-next-middleware.vercel.app/dashboard

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
balazsorban44commented, Apr 7, 2022

A fix has been released to canary, please test it out (npm i next@canary)

0reactions
github-actions[bot]commented, May 8, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

404 Page not found Vercel Deployment - using dynamic ...
When they create an application and then try to preview it, they are prompted with the 404 error. But if I trigger a...
Read more >
Custom 404 Page – Vercel Docs
Create a custom 404 page and deploy with Vercel. ... You can configure your router to handle the case when no route is...
Read more >
Data Fetching: getServerSideProps - Next.js
Learn how to fetch data on each request with Next.js. ... params : If this page uses a dynamic route, params contains the...
Read more >
Different History modes - Vue Router
Not to worry: To fix the issue, all you need to do is add a simple catch-all fallback route to your server. If...
Read more >
Next.js 12.2 Overview: Middleware, Layouts, and more
Next.js 12.2 introduces stable Middleware and On-Demand ISR, experimental Edge SSR and API Routes, and more.0:00 Intro1:50 Agenda2:30 ...
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