Skip to content

@next/next/no-server-import-in-page error occurs in nested route #35298

@kurone-ab

Description

@kurone-ab

Verify canary release

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

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 21.3.0: Wed Jan  5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T6000
Binaries:
  Node: 16.13.1
  npm: 8.5.4
  Yarn: 3.2.0-rc.10
  pnpm: N/A
Relevant packages:
  next: 12.1.1-canary.10
  react: 17.0.2
  react-dom: 17.0.2

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

./pages/foo/_middleware.ts
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

ESlint error occurs in nested route middleware not root middleware.
I think this error is similar to #32156

Expected Behavior

No lint error

To Reproduce

  1. Create nested foo directory in pages. (e.g. ./pages/foo)
  2. Create _middleware.ts file in foo.
  3. Run yarn lint.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions