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

@sachinnanne

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

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