Skip to content

[Bug?]: (cross-post) EBADF: bad file descriptor, fstat with latest NodeJS v25 releases #7065

Closed

Description

@jnoordsij

Self-service

  • I'd be willing to implement a fix

Describe the bug

(cross-post of nodejs/node#62012 which may be relevant and/or solvable here)

With the latest NodeJS v25 releases (>= 25.7.0), a variety of tooling (e.g. ESLint, Vite) runs into an immediate error when used with Yarn PnP:

Error: EBADF: bad file descriptor, fstat

This can also be observed on the latest test workflows for the master branch in this repository; see e.g. https://github.com/yarnpkg/berry/actions/runs/22605132315/job/65618028428.

From nodejs/node#62012 (comment):

Don't know if this has anything to do with their esm loader's load hook returning source: undefined when passed format: 'commonjs'. Looking at the debug output, createCJSModuleWrap was previously being called with translateContext.source fully populated, whereas it's now being called with translateContext.source: undefined.

This seems to suggest there may be a way to fix this here. Otherwise if this is a break in NodeJS behavior which should be addressed there, it might be worthwhile to post additional context on nodejs/node#62012.

To reproduce

  1. Install NodeJS v25.7.0 or higher
  2. Install Yarn through e.g. Corepack
  3. yarn init && yarn add -D eslint && yarn eslint

See also nodejs/node#62012 (comment).

Environment

System:
    OS: observed on Windows 11 10.0.26200 / Alpine 3.23 / MacOS (likely more)
    CPU: varying
  Binaries:
    Node: >= 25.7.0
    Yarn: 4.12.0

Additional context

Thanks a lot for spending any time looking into this!

Activity

  1. ZeWaka commented on Mar 17, 2026

    @ZeWaka

    Yep getting this too! Here are some debug logs if it helps assist.
    Using yarn 4.12.0 PnP, Node v25.8.1, rspack 1.7.8

    logspam

    MODULE 8692: Module._load checking cache for assert false
    MODULE 8692: load built-in module assert
    ESM 8692: Storing file:///X:/repos/goonstation/tgui/[eval1] (implicit type) in ModuleLoadMap
    ESM 8692: Storing file:///X:/repos/goonstation/tgui/[eval1] (implicit type) in ModuleLoadMap
    ESM 8692: ModuleJob.run() ModuleWrap {
      hasTopLevelAwait: false,
      sourceURL: undefined,
      sourceMapURL: undefined,
      synthetic: false,
      url: 'file:///X:/repos/goonstation/tgui/[eval1]',
      isMain: true
    }
    ESM 8692: async addJobsToDependencyGraph() file:///X:/repos/goonstation/tgui/[eval1] 
    ModuleJob {
        loader: ModuleLoader {
        loadCache: LoadCache(1) [Map] {
          'file:///X:/repos/goonstation/tgui/[eval1]' => [Object: null prototype]
        },
        isForAsyncLoaderHookWorker: false
      },
      importAttributes: [Object: null prototype] {},
      phase: 2,
      isMain: false,
      inspectBrk: false,
      url: 'file:///X:/repos/goonstation/tgui/[eval1]',
      module: ModuleWrap {
        hasTopLevelAwait: false,
        sourceURL: undefined,
        sourceMapURL: undefined,
        synthetic: false,
        url: 'file:///X:/repos/goonstation/tgui/[eval1]',
        isMain: true
      },
      modulePromise: Promise {
        ModuleWrap {
          hasTopLevelAwait: false,
          sourceURL: undefined,
          sourceMapURL: undefined,
          synthetic: false,
          url: 'file:///X:/repos/goonstation/tgui/[eval1]',
          isMain: true
        }
      },
      commonJsDeps: [],
      linked: [],
      instantiated: undefined
    }
    ESM 8692: Translating CJSModule file:///X:/repos/goonstation/tgui/.yarn/__virtual__/@rspack-core-virtual-f57d04e700/0/cache/@rspack-core-npm-1.4.11-6fbee5ea82-56a3a98f34.zip/node_modules/@rspack/core/dist/index.js [Object: null prototype] {  format: 'commonjs',
      responseURL: 'file:///X:/repos/goonstation/tgui/.yarn/__virtual__/@rspack-core-virtual-f57d04e700/0/cache/@rspack-core-npm-1.4.11-6fbee5ea82-56a3a98f34.zip/node_modules/@rspack/core/dist/index.js',
      source: undefined,
      translatorKey: 'commonjs'
    }
    Error: EBADF: bad file descriptor, fstat
        at tryStatSync (node:fs:386:25)
        at readFileSync (node:fs:442:17)
        at getSourceSync (node:internal/modules/esm/load:37:14)
        at createCJSModuleWrap (node:internal/modules/esm/translators:209:32)       
        at ModuleLoader.commonjsStrategy (node:internal/modules/esm/translators:348:10)
        at #translate (node:internal/modules/esm/loader:451:20)
        at afterLoad (node:internal/modules/esm/loader:507:29)
        at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:512:12)  
        at #getOrCreateModuleJobAfterResolve (node:internal/modules/esm/loader:555:36)
        at afterResolve (node:internal/modules/esm/loader:603:52) {
      errno: -4083,
      code: 'EBADF',
      syscall: 'fstat'
    }
    

  2. BinToss commented on Apr 6, 2026

    @BinToss

    I'm experiencing this issue with commitlint. Originally, it failed when opening commitlint's main module, but that was resolved by yarn unplug commitlint. Now, it occurs when accessing semver. Specifically, file:///home/noah/.yarn/berry/cache/semver-npm-7.7.4-746e538da5-10c0.zip/node_modules/semver/index.js

    $ yarn commitlint
    node:fs:386
      const stats = binding.fstat(fd, false, undefined, true /* shouldNotThrow */);
                            ^
    
    Error: EBADF: bad file descriptor, fstat
        at tryStatSync (node:fs:386:25)
        at readFileSync (node:fs:442:17)
        at getSourceSync (node:internal/modules/esm/load:37:14)
        at createCJSModuleWrap (node:internal/modules/esm/translators:211:32)
        at ModuleLoader.commonjsStrategy (node:internal/modules/esm/translators:350:10)
        at #translate (node:internal/modules/esm/loader:451:20)
        at afterLoad (node:internal/modules/esm/loader:507:29)
        at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:512:12)
        at #getOrCreateModuleJobAfterResolve (node:internal/modules/esm/loader:555:36)
        at afterResolve (node:internal/modules/esm/loader:603:52) {
      errno: -9,
      code: 'EBADF',
      syscall: 'fstat'
    }
    
    Node.js v25.9.0

    To learn which package(s) failed to load, I ran the CLI command in a javascript debugger and checked the path variable in the readFileSync part of the call stack.


    For now, I've locked down Engines in my package.json files and set up NVM.

  3. brandonbothell commented on Apr 22, 2026

    @brandonbothell
    Contributor

    Is this still happening to anyone else with yarn 4.14.1 on node v24.15 and >=25.7?

    I have to set my engines.node to >=18.0 <24.15 || >=25.0 <25.7 and use a strict node version check script in my .yarnrc.yml to guarantee compatibility without confusing errors.

    The following error occurs when running mocha with yarn.
    Mocha is its latest version, v11.7.5:

    λ yarn -v
    4.14.1
    
    λ yarn mocha --exit --require ts-node/register/transpile-only --require source-map-support/register --recursive \"./test/*.spec.ts\" --timeout 30000
    node:fs:391
      const stats = binding.fstat(fd, false, undefined, true /* shouldNotThrow */);
                            ^
    
    Error: EBADF: bad file descriptor, fstat
        at tryStatSync (node:fs:391:25)
        at readFileSync (node:fs:447:17)
        at getSourceSync (node:internal/modules/esm/load:37:14)
        at createCJSModuleWrap (node:internal/modules/esm/translators:210:32)
        at ModuleLoader.commonjsStrategy (node:internal/modules/esm/translators:349:10)
        at #translate (node:internal/modules/esm/loader:451:20)
        at afterLoad (node:internal/modules/esm/loader:507:29)
        at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:512:12)
        at #getOrCreateModuleJobAfterResolve (node:internal/modules/esm/loader:555:36)
        at afterResolve (node:internal/modules/esm/loader:603:52) {
      errno: -4083,
      code: 'EBADF',
      syscall: 'fstat'
    }
    
    Node.js v24.15.0
    
  4. jkowalleck commented on Apr 22, 2026

    @jkowalleck
    Contributor

    Is this still happening to anyone else with yarn 4.14.1 on node v24.15 and >=25.7?

    Tested: https://github.com/jkowalleck/playground_yarn4_EBADF_tests
    Test matrix results: https://github.com/jkowalleck/playground_yarn4_EBADF_tests/actions/runs/24769755781

    • still seeing the issue on node26-nightly ubuntu-latest
    • still seeing the issue on node26-nightly macos-latest
    • still seeing the issue on node25.9.0 ubuntu-latest
    • still seeing the issue on node25.9.0 macos-latest
    • still seeing the issue on node24.15.0 windows-latest
    • seams to be fixed on node26-nightly windows-latest
    • seams to be fixed on node25-nightly all
    • seams to be fixed on node25.9.0 windows-latest
  5. brandonbothell commented on Apr 22, 2026

    @brandonbothell
    Contributor
    * seams to be fixed on node25.9.0 windows-latest
    

    On windows 11 using nvm, I'm not sure if this is windows-latest

    > nvm use 25.9                                                  
    Now using node v25.9.0 (64-bit)
    > yarn test:http            
    node:fs:386
      const stats = binding.fstat(fd, false, undefined, true /* shouldNotThrow */);
                            ^
    
    Error: EBADF: bad file descriptor, fstat
        at tryStatSync (node:fs:386:25)
        at readFileSync (node:fs:442:17)
        at getSourceSync (node:internal/modules/esm/load:37:14)
        at createCJSModuleWrap (node:internal/modules/esm/translators:211:32)
        at ModuleLoader.commonjsStrategy (node:internal/modules/esm/translators:350:10)
        at #translate (node:internal/modules/esm/loader:451:20)
        at afterLoad (node:internal/modules/esm/loader:507:29)
        at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:512:12)
        at #getOrCreateModuleJobAfterResolve (node:internal/modules/esm/loader:555:36)
        at afterResolve (node:internal/modules/esm/loader:603:52) {
      errno: -4083,
      code: 'EBADF',
      syscall: 'fstat'
    }
    
    Node.js v25.9.0
    
  6. tfp-rv commented on Apr 24, 2026

    @tfp-rv

    Can confirm, also still experiencing this on Windows with yarn 4.14.1 and node 25.9.0.

  7. arcanis commented on Apr 24, 2026

    @arcanis
    Member

    Node.js fixed the regression, we're waiting for the next 24.x and 25.x releases

  8. brandonbothell commented on Apr 24, 2026

    @brandonbothell
    Contributor

    Node.js fixed the regression, we're waiting for the next 24.x and 25.x releases

    For anyone else that was curious, I guess this was because yarn patches the 'fs' api to add support for .zip files before node uses it in its ESM loader, and a recent node update affected the loading order of modules so that the unpatched versions of fs functions would be cached before yarn and other modules would patch them.

    It appears that a simple update was all that was needed for now, which loads the fs methods needed by the ESM loader upon their use instead of caching them upon module load (before yarn can patch them)

    It seems that node may not leave FS patchable like this forever, but at the same time there is a virtual filesystem PR under review that looks promising. Hopefully we won't have to deal with these random fs issues for much longer, then.

  9. jkowalleck commented on Apr 25, 2026

    @jkowalleck
    Contributor

    Node.js fixed the regression, we're waiting for the next 24.x and 25.x releases

    confirm and agree.


    re #7065 (comment)

    Tested: https://github.com/jkowalleck/playground_yarn4_EBADF_tests
    Test matrix results: https://github.com/jkowalleck/playground_yarn4_EBADF_tests/actions/runs/24923966694

    • seams to be fixed on node26-nightly ubuntu-latest
    • seams to be fixed on node26-nightly windows-latest
    • seams to be fixed on node26-nightly macos-latest
    • seams to be fixed on node25-nightly ubuntu-latest
    • seams to be fixed on node25-nightly windows-latest
    • seams to be fixed on node25-nightly macos-latest

    waiting for the next 24.x and 25.x releases

  10. jkowalleck commented on May 6, 2026

    @jkowalleck
    Contributor

    addded node26 and node24-nightly to my tests:

    Tested: https://github.com/jkowalleck/playground_yarn4_EBADF_tests
    Test matrix results: https://github.com/jkowalleck/playground_yarn4_EBADF_tests/actions/runs/25425869432

    used yarn v4.14.1

    findings

    • node26-nightly - worked on all
    • node25-nightly - worked on all
    • node24-nightly - worked on all
    • node26 v26.0.0 - worked on windows
    • node26 v26.0.0 - failed on ubuntu
    • node26 v26.0.0 - failed on macOS
    • node25 v25.9.0 - worked on windows
    • node25 v25.9.0 - failed on ubuntu
    • node25 v25.9.0 - failed on macOS
    • node24 v24.14.1 - worked on ubuntu
    • node24 v24.14.1 - failed on windows
    • node24 v24.14.1 - failed on macOS
    • node 22 and below: just worked
  11. jnoordsij commented on May 6, 2026

    @jnoordsij
    Author

    nodejs/node#62835 did not make it to 26.0.0 unfortunately, but is in 26.1.0 so hopefully from there on things are working. No idea when 24/25 are receiving new releases, but the fix should be in the respective branches already.

    (and from what it seems test matrix above seems to confirm this claim)

  12. added a commit that references this issue on May 17, 2026
  13. SparK-Cruz commented on May 18, 2026

    @SparK-Cruz

    Failing on both ubuntu and manjaro, node 25.9

  14. added a commit that references this issue on May 19, 2026
  15. jnoordsij commented on Jul 23, 2026

    @jnoordsij
    Author

    This should be fixed now on all supported Node.js versions. 25 is considered EOL and as such will never receive a fix for this anymore.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions