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

next/server should not be imported outside of pages/_middleware.js #32121

Closed
saurabhguptarock opened this issue Dec 4, 2021 · 2 comments · Fixed by #32139
Closed

next/server should not be imported outside of pages/_middleware.js #32121

saurabhguptarock opened this issue Dec 4, 2021 · 2 comments · Fixed by #32139
Labels
Linting Related to `next lint` or ESLint with Next.js.

Comments

@saurabhguptarock
Copy link

saurabhguptarock commented Dec 4, 2021

What version of Next.js are you using?

12.0.6

What version of Node.js are you using?

14.18.2

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

Vercel

Describe the Bug

I have added _middleware.tsx file in /pages/login/_middleware.tsx and it gives error.

Expected Behavior

It should not give any error

To Reproduce

My files

_middleware.tsx

import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";

export const middleware = (req: NextRequest) => {
  const cookie = req.cookies["auth"];

  if (cookie) {
    return NextResponse.redirect("/");
  }
};

Folder structure
Screenshot 2021-12-04 at 7 29 54 PM

Screenshot 2021-12-04 at 7 30 06 PM

@saurabhguptarock saurabhguptarock added the bug Issue was opened via the bug report template. label Dec 4, 2021
@balazsorban44 balazsorban44 added Linting Related to `next lint` or ESLint with Next.js. kind: bug and removed bug Issue was opened via the bug report template. labels Dec 5, 2021
@balazsorban44
Copy link
Member

This is being addressed in #32139

@kodiakhq kodiakhq bot closed this as completed in #32139 Dec 5, 2021
kodiakhq bot pushed a commit that referenced this issue Dec 5, 2021
…2139)

People have been reporting on #30973 that the `no-server-import-in-page` eslint rule is reporting false positives for `_middleware` files inside sub-page folders.

Unlike `_document`, we can have multiple `_middleware` files.

Fixes #32121
@balazsorban44
Copy link
Member

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.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
natew pushed a commit to natew/next.js that referenced this issue Feb 16, 2022
…rcel#32139)

People have been reporting on vercel#30973 that the `no-server-import-in-page` eslint rule is reporting false positives for `_middleware` files inside sub-page folders.

Unlike `_document`, we can have multiple `_middleware` files.

Fixes vercel#32121
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Linting Related to `next lint` or ESLint with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants