Skip to content

[ESLint v10]: TypeError: contextOrFilename.getFilename is not a function when running ESLint v10 #89764

Open
quachtridat/quachtridat.github.io
#28

Description

@bennajah

Link to the code that reproduces this issue

https://github.com/bennajah/nextjs16

To Reproduce

  1. Create a next.js project or clone this repo
  2. Upgrade eslint to v10 .
  3. Run eslint

Current vs. Expected behavior

After upgrading ESLint to v10 in a Next.js project, running bun eslint causes the following error:

PS C:\Users\benna\dev\my-app> bun lint
$ eslint

Oops! Something went wrong! :(

ESLint: 10.0.0

TypeError: Error while loading rule 'react/display-name': contextOrFilename.getFilename is not a function
Occurred while linting C:\Users\benna\dev\my-app\app\layout.tsx
    at resolveBasedir (C:\Users\benna\dev\my-app\node_modules\eslint-plugin-react\lib\util\version.js:31:100)
    at detectReactVersion (C:\Users\benna\dev\my-app\node_modules\eslint-plugin-react\lib\util\version.js:85:19)
    at getReactVersionFromContext (C:\Users\benna\dev\my-app\node_modules\eslint-plugin-react\lib\util\version.js:116:25)
    at testReactVersion (C:\Users\benna\dev\my-app\node_modules\eslint-plugin-react\lib\util\version.js:181:28)
    at usedPropTypesInstructions (C:\Users\benna\dev\my-app\node_modules\eslint-plugin-react\lib\util\usedPropTypes.js:307:36)
    at Components.componentRule (C:\Users\benna\dev\my-app\node_modules\eslint-plugin-react\lib\util\Components.js:940:37)
    at createRuleListeners (C:\Users\benna\dev\my-app\node_modules\eslint\lib\linter\linter.js:497:15)
    at C:\Users\benna\dev\my-app\node_modules\eslint\lib\linter\linter.js:623:7
    at Array.forEach (<anonymous>)
    at runRules (C:\Users\benna\dev\my-app\node_modules\eslint\lib\linter\linter.js:557:31)

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 12244
  Available CPU cores: 8
Binaries:
  Node: 24.13.0
  npm: 11.6.2
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 16.1.6 // Latest available version is detected (16.1.6).
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Linting

Which stage(s) are affected? (Select all that apply)

Other (Deployed)

Additional context

No response

Activity

  1. added theissue type on Feb 10, 2026
  2. added
    Linting
    on Feb 10, 2026
  3. simonhudson commented on Feb 11, 2026

    @simonhudson

    Also seeing same error for react/no-direct-mutation-state rule when running Lint in GH actions

    Image
  4. jWytrzes commented on Feb 12, 2026

    @jWytrzes

    Same here and also same with react/no-direct-mutation-state as mentioned

    EDIT: And when I turn off both of them it changes to react/no-render-return-value, so probably it can go on like that

  5. added
    linear: next
    on Feb 16, 2026
  6. OscarGauss commented on Feb 19, 2026

    @OscarGauss

    Temporary Fix for ESLint v10:
    This error happens because eslint-plugin-react (a dependency of eslint-config-next) uses the legacy context.getFilename() API for version auto-detection, which was removed in ESLint v10.
    To fix this, you must explicitly define your React version in your eslint.config.mjs settings to bypass the auto-detection logic.
    I've created a Gist with the corrected configuration for Next.js + ESLint 10: "Next.js ESLint v10 Fix"
    Key change:

    {
      settings: {
        react: { version: "19" } // Avoids auto-detection crash
      }
    }
  7. added a commit that references this issue on Feb 24, 2026
  8. t6adev commented on Feb 25, 2026

    @t6adev

    It should be work for some cases.
    https://www.npmjs.com/package/@eslint/compat

  9. 44 remaining items

  10. lusu007 commented on Jul 29, 2026

    @lusu007

    @icyJoseph ESLint 9 reaches end of life on August 6, 2026, so users relying on eslint-config-next will be left without a supported ESLint version next week (https://eslint.org/version-support/).

    What is the current plan for resolving the ESLint 10 compatibility issues? Given the approaching EOL date, this should be escalated and prioritized to avoid forcing users to remain on an unsupported ESLint release.

  11. icyJoseph commented on Jul 29, 2026

    @icyJoseph
    Member

    Hi, @lusu007 - I'd love to resolve this issue too. It is one of the most reacted ones.

    From my notes, we still need jsx-eslint/eslint-plugin-react#3979 to land, right?

    We considered kind of applying the workaround at the top, but that's probably not a good idea.

  12. lusu007 commented on Jul 29, 2026

    @lusu007

    Thanks for the response @icyJoseph. Yes, jsx-eslint/eslint-plugin-react#3979 seems to be the immediate blocker.

    However, this also highlights a broader dependency and governance problem: critical tooling used by projects like Next.js can be blocked by a very small number of external maintainers. With ESLint 9 reaching EOL next week, is there anything the Next.js team could do to help move this forward or provide some guidance on a fallback?

    It may also be worth considering a more resilient long-term approach, since a similar situation could otherwise arise again with a future breaking ESLint release.

  13. icyJoseph commented on Jul 29, 2026

    @icyJoseph
    Member

    @lusu007 IIRC, the workaround from #89764 (comment) should do the trick? You can take ESLint 10, and prevent the version auto detection branch from crashing?

  14. mmilanovic4 commented on Jul 31, 2026

    @mmilanovic4

    For JavaScript-only projects the settings.react.version pin isn't enough on its own — linting still fails before reaching the react rules:

    TypeError: scopeManager.addGlobals is not a function
        at addDeclaredGlobals (eslint/lib/languages/js/source-code/source-code.js:221:15)
    

    eslint-config-next parses JS/JSX with Next's bundled @babel/eslint-parser (exposed as eslint-config-next/parser), whose scope manager predates ESLint 10's ScopeManager#addGlobals. TypeScript projects don't hit it because eslint-config-next/typescript swaps in @typescript-eslint/parser.

    Overriding both works on eslint@10.8.0 / eslint-config-next@16.2.12:

    import tsParser from "@typescript-eslint/parser";
    import nextVitals from "eslint-config-next/core-web-vitals";
    
    export default [
      ...nextVitals,
      {
        languageOptions: {
          parser: tsParser,
          parserOptions: { ecmaFeatures: { jsx: true } },
        },
        settings: {
          react: { version: "19" },
        },
      },
    ];

    Needs @typescript-eslint/parser@>=8.65.0 — the first version declaring eslint: ^10 in its peer range. Caveat: this drops Babel parsing for JS files, so next/babel-specific syntax would no longer parse.

    To be clear, this is a stopgap and not something anyone should have to keep in their config long-term — I'm posting it mainly so JS projects aren't blocked in the meantime. Hoping eslint-config-next can support ESLint 10 out of the box once jsx-eslint/eslint-plugin-react#3979 lands.

  15. KeroZelvin commented on Aug 2, 2026

    @KeroZelvin

    Confirming the two-part workaround above in a mixed JavaScript/TypeScript production app:

    • Node 24.18.1, npm 11.16.0, next / eslint-config-next 16.2.12, and ESLint 10.8.0.
    • Pinning settings.react.version to "19" cleared the initial contextOrFilename.getFilename crash, but JavaScript and MJS files then failed at scopeManager.addGlobals.
    • Adding @typescript-eslint/parser@8.65.0 only for **/*.{js,mjs,cjs,jsx} fixed that second failure while leaving the TypeScript parser configuration intact.
    • A clean npm ci, full lint, tsc --noEmit, next build, and the complete CI suite all passed; the same artifact completed its production release checks.

    The scoped override is important for mixed projects; applying the parser globally can unnecessarily replace the TypeScript config inherited from eslint-config-next/typescript.

    One remaining caveat: npm still reports ESLint peer-range warnings from the bundled React, import, and jsx-a11y plugins. They did not block this release, but this is still a stopgap rather than out-of-the-box ESLint 10 support.

  16. cbartens commented on Aug 11, 2026

    @cbartens

    Adding a workaround for the reported crash, plus a second blocker that sits behind it.

    Workaround for contextOrFilename.getFilename is not a function

    eslint-config-next sets settings.react.version = 'detect' (dist/index.js:143). eslint-plugin-react only calls detectReactVersion() when the configured version is literally the string 'detect' (lib/util/version.js:113-116), and that is the path that reaches the removed context.getFilename() (version.js:31).

    Pinning an explicit version after the config spread skips that branch entirely:

    // eslint.config.js
    import nextCoreWebVitals from "eslint-config-next/core-web-vitals";
    
    export default [
      ...nextCoreWebVitals,
      { settings: { react: { version: "19.2.4" } } }, // your React version
    ];

    Confirmed on eslint 10.8.1 + eslint-config-next 16.3.0 + React 19.2.4: the react/display-name / getFilename error no longer occurs.

    But this is not a full fix — a second blocker follows

    With the above applied, linting fails at the next step:

    TypeError: scopeManager.addGlobals is not a function
        at addDeclaredGlobals (eslint/lib/languages/js/source-code/source-code.js:221:15)
        at SourceCode.finalize (source-code.js:1090:3)
    

    ESLint 10 calls scopeManager.addGlobals() whenever a config declares languageOptions.globals under a custom parser. eslint-config-next declares 1174 globals, so this always fires.

    The parser is Next's own:

    $ npx eslint --print-config <file>
    parser: eslint-config-next/parser@16.2.10
    
    // eslint-config-next/dist/parser.js
    var _eslintparser = require("next/dist/compiled/babel/eslint-parser");

    addGlobals appears 0 times in next/dist/compiled/babel/eslint-parser.

    Why this points at the vendored Babel version

    Babel has addressed this directly and ruled out a Babel 7 fix:

    Both closed as duplicates pointing to Babel 8.

    So eslint-config-next appears blocked on Next vendoring Babel 8's @babel/eslint-parser, independent of the eslint-plugin-react issue in the title.

    For reference, this is not typescript-eslint: @typescript-eslint/scope-manager implements addGlobals (dist/ScopeManager.js:106) since ~8.55.0, per typescript-eslint#11762.

    Scope

    In a pnpm monorepo, only the Next app is affected — packages using a plain typescript-eslint flat config (no globals block) lint clean on eslint 10.8.1. So this is isolated to eslint-config-next, not a general ESLint 10 migration problem.

  17. nanduxdev commented on Sep 16, 2026

    @nanduxdev

    Got the same error reacr/display-name:
    Oops! Something went wrong! :(

    ESLint: 10.10.0

    TypeError: Error while loading rule 'react/display-name': contextOrFilename.getFilename is not a function
    Occurred while linting /Users/nandannagane/Desktop/skill-trail/app/auth/layout.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

LintingUpstreamlinear: next

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions