rushstack icon indicating copy to clipboard operation
rushstack copied to clipboard

[eslint-patch] Failed to patch ESLint when using next/core-web-vitals configuration

Open gs0428 opened this issue 11 months ago • 8 comments

Summary

I encountered an issue while trying to lint a Next.js project using pnpm dlx eslint with the next/core-web-vitals configuration. The ESLint process fails when this configuration is included but works fine when it is removed or commented out. This issue appears to involve @rushstack/eslint-patch in combination with eslint-config-next.

Repro steps

  1. Create a new Next.js project using the following command
pnpm dlx create-next-app my-app
  1. Navigate to the project directory
cd my-app
  1. Default eslint.config.mjs file is like below
import { dirname } from "path";
import { fileURLToPath } from "url";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const compat = new FlatCompat({
  baseDirectory: __dirname,
});

const eslintConfig = [
  ...compat.extends("next/core-web-vitals", "next/typescript"),
];

export default eslintConfig;
  1. Run the following command to lint the page.tsx file
pnpm dlx eslint src/app/page.tsx

Expected result: The file should be linted without any issues.

Actual result: The following error is displayed

Oops! Something went wrong! :(

ESLint: 9.17.0

Error: Cannot read config file: /Users/gwangsoo/Desktop/my-app/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/eslint-config-next/index.js
Error: Failed to patch ESLint because the calling module was not recognized.
If you are using a newer ESLint version that may be unsupported, please create a GitHub issue:
https://github.com/microsoft/rushstack/issues
Referenced from: /Users/gwangsoo/Desktop/my-app/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/eslint-config-next/core-web-vitals.js
    ...
  1. Workaround
  • Commenting out the next/core-web-vitals configuration in eslint.config.mjs resolves the issue.
const eslintConfig = [
  // ...compat.extends("next/core-web-vitals"),
  ...compat.extends("next/typescript"),
];
  • With the above change, the linting process works as expected.

Details

The issue occurs specifically when the next/core-web-vitals configuration is included in the ESLint configuration. Removing this configuration prevents the error. The root cause seems to involve @rushstack/eslint-patch and its handling of this configuration, possibly due to module resolution or versioning conflicts.

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
Package name: @rushstack/eslint-patch
Package version? 1.10.4
Operating system? MacOS
Would you consider contributing a PR? Yes
Node.js version (node -v)? v20.17.0

gs0428 avatar Dec 17 '24 15:12 gs0428