@next/next/no-server-import-in-page throws error on nested _middleware
See original GitHub issueWhat version of Next.js are you using?
12.0.7
What version of Node.js are you using?
v12.22.6
What browser are you using?
Chrome
What operating system are you using?
macOS
How are you deploying your application?
Vercel
Describe the Bug
@next/next/no-server-import-in-page rule throws error on nested _middleware.js.
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
This rules should behave the same way for nested and root _middleware.js
To Reproduce
Create 2 _middleware.js, one in ./pages/_middleware.js
and the other in ./pages/nested/_middleware.js
with the same code and import import { NextResponse } from "next/server";
.
Code Example: https://replit.com/@francofantini/no-server-import-in-page-bug
Run npm run lint
on this repo and you’ll see that the rule @next/next/no-server-import-in-page
fails for ./pages/link/_middleware.js
but not for ./pages/_middleware.js
.
$ npm run lint
> next12@0.1.0 lint /home/runner/no-server-import-in-page-bug
> next lint
./pages/link/_middleware.js
1:1 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
info - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! next12@0.1.0 lint: `next lint`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the next12@0.1.0 lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2021-12-06T00_35_02_565Z-debug.log
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:6 (4 by maintainers)
Top GitHub Comments
Hello!
Yes it has been fixed and released on v12.0.8-canary.0.
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.