Skip to content

[BUG] HAS_BROKEN_FSTAT_FOR_ZIP_FDS version gate should include Node 24.15+ #7103

Closed

Description

@rfoel

What's the problem?

PR #7070 fixed the EBADF: bad file descriptor, fstat error for Node 25.7+ by reading CJS source of zip files instead of letting Node fstat the fake fd. However, the version gate only checks for Node >= 25.7:

export const HAS_BROKEN_FSTAT_FOR_ZIP_FDS = major > 25 || (major === 25 && minor >= 7);

The same breaking change from nodejs/node#61769 (lib: reduce cycles in esm loader and load it in snapshot, commit ad1078c0) was backported to Node v24.15.0, causing the identical EBADF error on that version.

Confirmed by checking the commits between v24.14.1 and v24.15.0 — PR nodejs/node#61769 is included.

Reproduction

$ node --version
v24.15.0

$ yarn --version
4.14.0

$ yarn install
➤ YN0009: │ unrs-resolver@npm:1.11.1 couldn't be built successfully (exit code 1)
➤ YN0009: │ argon2@npm:0.44.0 couldn't be built successfully (exit code 1)

Build log:

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)
    ...

Works fine on Node v24.14.1, fails on v24.15.0.

Suggested fix

Widen the version gate in packages/yarnpkg-pnp/sources/esm-loader/loaderFlags.ts to also cover Node 24.15+:

export const HAS_BROKEN_FSTAT_FOR_ZIP_FDS = major > 25 || (major === 25 && minor >= 7) || (major === 24 && minor >= 15);

Activity

  1. mhassan1 commented on Apr 16, 2026

    @mhassan1
    Contributor

    Duplicate of #7102 (which seems like it was closed prematurely)

  2. added a commit that references this issue on Apr 16, 2026
    108a4dc
  3. changed the title [-]fix: HAS_BROKEN_FSTAT_FOR_ZIP_FDS version gate should include Node 24.15+[/-] [+][BUG] HAS_BROKEN_FSTAT_FOR_ZIP_FDS version gate should include Node 24.15+[/+] on Apr 16, 2026
  4. arcanis commented on Apr 17, 2026

    @arcanis
    Member

    Indeed I completely forgot this would need to be updated. This is fixed in 4.14.1

  5. 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
    
  6. shankar-krishna commented on May 2, 2026

    @shankar-krishna

    Still facing same with yarn version 4.14.1 and node 24.15.0.

    `# This file contains the result of Yarn building a package (unrs-resolver@npm:1.11.1)

    Script name: postinstall

    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'
    }`

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions