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.

@next/next/no-server-import-in-page ESLint rule throws on test files

See original GitHub issue

Verify canary release

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

Provide environment information

    Operating System:
      Platform: linux
      Arch: x64
      Version: #1 SMP Tue Jun 23 12:58:10 UTC 2020
    Binaries:
      Node: 16.14.2
      npm: 8.5.0
      Yarn: 3.2.0
      pnpm: N/A
    Relevant packages:
      next: 12.1.6
      react: 18.1.0
      react-dom: 18.1.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Vercel

Describe the Bug

When a test file in the pages folder exists that imports next/server, the rule @next/next/no-server-import-in-page throws during next build.

Expected Behavior

Test files, either those in __tests__ or file.test.ts should be ignored for this rule

To Reproduce

package.json

    "@typescript-eslint/parser": "^5.25.0",
    "eslint": "^8.15.0",
    "eslint-config-next": "^12.1.6",
    "eslint-plugin-react": "^7.29.4",

.eslint.json

{
  "root": true,
  "extends": "next/core-web-vitals",
  "parser": "@typescript-eslint/parser"
}

Create a file at pages/__tests__/example.test.ts

import "jest";
import { NextRequest } from "next/server";

describe("example", () => {
  it("should pass", () => {});
});

Run next build or deploy to Vercel

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Shubhamchindacommented, Jun 21, 2022

@Shubhamchinda are you planning to work on this or could I take it over?

@aboqasem Please take it.

1reaction
rikkitcommented, Jun 8, 2022

@Shubhamchinda go for it

Read more comments on GitHub >

github_iconTop Results From Across the Web

eslint doesn't recognize rule violations in test files and built-in ...
I'm expecting failing tests and linter errors but both are passing... The funny thing: When deleting the lib folder, at least the linter...
Read more >
Unit Tests - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Writing custom TypeScript Eslint rules with unit tests for ...
After reading this article you will know how to create a custom Eslint rule in Typescript for Angular project and how to test...
Read more >
Guide to JUnit 4 Rules - Baeldung
As we can see, we first define the TemporaryFolder rule tmpFolder. Next, our test method creates a file called test-file.txt in the temporary ......
Read more >
Working and unit testing with temporary files in Java
@Rule public TemporaryFolder folder = new TemporaryFolder(); /* executed before every test: create temporary files */ @Before public void ...
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