Skip to content

[Bug?]: Yarn: 3.6.3 with Playwright CLI fails with EBADF: bad file descriptor, fstat error when used in Yarn PnP environments, preventing CLI-based test execution #7037

Closed as not planned

Description

@sachinnanne

Self-service

  • I'd be willing to implement a fix

Describe the bug

Yarn 3.6.3 with Playwright CLI returns an EBADF: bad file descriptor, fstat error in Yarn PnP environments, blocking CLI test runs. Playwright reports it works as expected with Yarn v4.
Is this issue specific to Yarn 3.6.3 versus v4?

Issue submitted with playwright

To reproduce

Version

1.57.0 (also tested: 1.40.0, 1.30.0)

Steps to reproduce

Reproduction Steps

1. Create Yarn PnP Project

mkdir playwright-yarn-pnp-test
cd playwright-yarn-pnp-test
yarn init -y
echo "nodeLinker: pnp" > .yarnrc.yml

2. Install Playwright

yarn add --dev @playwright/test playwright playwright-core

3. Create Test File

// test.spec.js
const { test, expect } = require('@playwright/test');

test('basic test', async ({ page }) => {
  await page.goto('https://example.com');
  await expect(page).toHaveTitle(/Example/);
});

4. Create Playwright Config

// playwright.config.js
module.exports = {
  testDir: '.',
  testMatch: ['**/*.spec.js']
};

5. Run Test (Fails)

yarn playwright test
# Results in EBADF error

6. Verify PnP Environment

ls .yarn/cache/ | grep playwright

### Expected behavior

## Expected Behavior
Playwright CLI should work with Yarn PnP environments, allowing test execution via:
```bash
yarn playwright test

Actual behavior

Actual Behavior

CLI fails with EBADF error when trying to read test files from Yarn PnP's virtual filesystem:

Error: EBADF: bad file descriptor, fstat
    at tryStatSync (node:fs:392:25)
    at readFileSync (node:fs:448:17)
    at getSourceSync (node:internal/modules/esm/load:66:14)
    at getSource (node:internal/modules/esm/translators:65:10)
    at createCJSModuleWrap (node:internal/modules/esm/translators:181:32)
    at ModuleLoader.commonjsStrategy (node:internal/modules/esm/translators:271:10)
    at #translate (node:internal/modules/esm/loader:468:12)
    at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:515:27)
    at async ModuleJob._link (node:internal/modules/esm/module_job:115:19) {
  errno: -9,
  code: 'EBADF',
  syscall: 'fstat'
}

Additional context

Root Cause Analysis

The issue occurs because:

  1. Yarn PnP stores packages in zip archives (.yarn/cache/*.zip)
  2. Playwright CLI uses fs.readFileSync() and fstat to read test files
  3. Virtual file descriptors from zip archives cause fstat to fail with EBADF

What We've Tested (All Failed)

Solution Result Notes
Reinstall Playwright ❌ Failed Same EBADF error
Different Playwright versions ❌ Failed 1.57.0, 1.40.0 both fail
Clear Yarn cache ❌ Failed Fresh install doesn't help
Explicit config files ❌ Failed CLI still can't read files
Add missing dependencies ❌ Failed Fixed playwright-core but EBADF persists

Environment

System:
    OS: macOS 26.2
    CPU: (10) arm64 Apple M1 Max
    Memory: 485.47 MB / 32.00 GB
  Binaries:
    Node: 22.14.0 - ~/.nvm/versions/node/v22.14.0/bin/node
    Yarn: 3.6.3 - /opt/homebrew/bin/yarn
    npm: 10.9.2 - ~/.nvm/versions/node/v22.14.0/bin/npm
  Languages:
    Bash: 3.2.57 - /bin/bash

Environment

System:
    OS: macOS 26.2
    CPU: (10) arm64 Apple M1 Max
    Memory: 485.47 MB / 32.00 GB
  Binaries:
    Node: 22.14.0 - ~/.nvm/versions/node/v22.14.0/bin/node
    Yarn: 3.6.3 - /opt/homebrew/bin/yarn
    npm: 10.9.2 - ~/.nvm/versions/node/v22.14.0/bin/npm
  Languages:
    Bash: 3.2.57 - /bin/bash

Additional context

No response

Activity

  1. clemyan commented on Jan 20, 2026

    @clemyan
    Member

    Seems like it was fixed in #5961. Can you upgrade to at least 3.7.0 and try?

  2. sachinnanne commented on Jan 21, 2026

    @sachinnanne
    Author

    The EBADF issue is SOLVED by upgrading to Yarn 3.7.0+ but new error - buffer concatenation problems with image files.
    Why: The rimraf cleanup process might be passing incorrect data types to Buffer.concat.

    Buffer Concatenation Error in Yarn PnP 3.7.0

    Environment:
    - Yarn: 3.7.0
    - Node.js: 22.14.0  
    - Context: Playwright test cleanup operations
    
    Error:
    TypeError: The "list[1]" argument must be an instance of Buffer or Uint8Array.
    Received type string ('abc.png')
    at Function.concat (node:buffer:602:13)
    at node:internal/fs/rimraf:145:32
    at .pnp.cjs:19356:13
    

    Trigger: File cleanup operations on PNG files and .last-run.json during test cleanup

    Impact: Prevents successful completion of Playwright tests in Yarn PnP environments

    But GOOD NEWS, when upgrading to yarn v4.12.0 everything is working

    YARN V4 COMPLETELY FIXED THE ISSUES:
    ✅ No EBADF error - Completely resolved!
    ✅ No Buffer concatenation error - Completely resolved!
    ✅ Playwright CLI WORKING - Running tests across all browsers!

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 workingwaiting for feedbackWill autoclose in a while unless more data are provided

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions