eslint / config-inspector

A visual tool for inspecting and understanding your ESLint flat configs.
https://www.npmjs.com/package/@eslint/config-inspector
Apache License 2.0
723 stars 19 forks source link

Failed to load `eslint.config.js` when shareable config uses `@rushstack/eslint-patch` #70

Open r34son opened 4 months ago

r34son commented 4 months ago
image

eslint.config.mjs:

import path from 'node:path';
import { fileURLToPath } from 'node:url';
import js from '@eslint/js';
import { fixupConfigRules, includeIgnoreFile } from '@eslint/compat';
import { FlatCompat } from '@eslint/eslintrc';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
  baseDirectory: __dirname,
  recommendedConfig: js.configs.recommended,
  allConfig: js.configs.all,
});
const gitignorePath = path.resolve(__dirname, '.gitignore');

/** @type { import("eslint").Linter.FlatConfig[] } */
export default [
  includeIgnoreFile(gitignorePath),
  ...fixupConfigRules(
    compat.extends('next/core-web-vitals'),
  ),
];
Full error ``` Failed to load eslint.config.js Error: Cannot read config file: /Users/seitasanov/ownProjects/profile/node_modules/.pnpm/eslint-config-next@15.0.0-canary.39_eslint@9.5.0_typescript@5.5.2/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/seitasanov/ownProjects/profile/node_modules/.pnpm/eslint-config-next@15.0.0-canary.39_eslint@9.5.0_typescript@5.5.2/node_modules/eslint-config-next/core-web-vitals.js ```
voxpelli commented 3 months ago

Can you make a more minimal reproduction of the issue?

kachkaev commented 2 weeks ago

@voxpelli I can observe this issue in the latest Config Inspector (0.5.5) when creating a new Next.js project (15.0.1). Versions below are pinned for reproducibility:

cd /tmp

npx create-next-app@15.0.1 --use-npm --yes config-inspector-issue-70
cd config-inspector-issue-70

npx @eslint/migrate-config .eslintrc.json
npm install @eslint/js @eslint/eslintrc -D
rm .eslintrc.json

npm install

npx @eslint/config-inspector@0.5.5
ℹ Starting ESLint config inspector at http://localhost:7777 

ℹ Reading ESLint config from /private/tmp/config-inspector-issue-70/eslint.config.mjs
Failed to load `eslint.config.js`.
Note that `@eslint/config-inspector` only works with the flat config format:
https://eslint.org/docs/latest/use/configure/configuration-files-new
Error: Cannot read config file: /private/tmp/config-inspector-issue-70/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: /private/tmp/config-inspector-issue-70/node_modules/eslint-config-next/core-web-vitals.js
    at Object.<anonymous> (/private/tmp/config-inspector-issue-70/node_modules/@rushstack/eslint-patch/lib/_patch-base.js:167:19)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Module._load (node:internal/modules/cjs/loader:1104:12)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/private/tmp/config-inspector-issue-70/node_modules/@rushstack/eslint-patch/lib/modern-module-resolution.js:11:23)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)

Must be this line: https://github.com/vercel/next.js/blob/655b808c5b352350fe85c0fadc7b92ff251e675b/packages/eslint-config-next/index.js#L53