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.

Middleware won't deploy in subpath with error no-server-import-in-page with React Server Components and concurrentFeatures

See original GitHub issue

What version of Next.js are you using?

12.0.8-canary.4

What version of Node.js are you using?

local: 14.8.1 // vercel: 12

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

Vercel

Describe the Bug

When deploying an NextJs App to Vercel, with having a _middleware.js / _middleware.ts in a sub-path of pages, e.g. /pages/dashboard/_middleware.ts the build fails with: Error: next/server should not be imported outside of pages/_middleware.js. See https://nextjs.org/docs/messages/no-server-import-in-page. @next/next/no-server-import-in-page

Expected Behavior

Deploy sucessfully

To Reproduce

With: concurrentFeatures: true serverComponents: true

Add: /pages/test/_middleware.js

import { NextResponse } from "next/server";

export default async function middleware(req, event) {
  return NextResponse.next();
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
balazsorban44commented, Dec 14, 2021

@thibautsabot is totally right.

This has been fixed in eslint-config-next@12.0.8-canary.0. Make sure you have that or a newer version!

1reaction
thibautsabotcommented, Dec 14, 2021

Hey!

Really sorry about the hiccup 🙏 .

I’m unable to reproduce it with next and eslint-config-next on 12.0.8-canary.5 though 😕 . Did you update both packages?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Server Components in Next.js 12
Next.js 12 includes React Server Components, which enable you to load components faster because computing is shifted away from the client.
Read more >
React 18: React Server Components
React Server Components allow developers to build applications that span the server and ... Deploy the app/ directory example to try Server Components....
Read more >
Introducing Zero-Bundle-Size React Server Components
As it comes to an end we wanted to share a special Holiday Update on our research into zero-bundle-size React Server Components.
Read more >
javascript - Error: `experimental.runtime` requires ...
Remove your package-lock.json and install the canary version of next npm install next@canary react@latest react-dom@latest.
Read more >
React Server Components. - It's not server-side rendering.
log(error); }); }, []);. Although there's nothing wrong with that, this data fetching approach will always cost some time to render ...
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