Skip to content

[Bug?]: Recursive readdirSync returns relative parentPath inside zip archives #7315

Open

Description

@eugeniodepalo

Self-service

  • I'd be willing to implement a fix

Describe the bug

Under PnP, fs.readdirSync(dir, { recursive: true, withFileTypes: true }) on a directory inside a package zip returns entries whose parentPath is relative to dir ("classes"). Node returns the absolute directory ("/…/node_modules/semver/classes"), so code that does path.join(entry.parentPath, entry.name) gets the wrong path and fails with ENOENT.

To reproduce

package.json:

{ "name": "repro", "private": true, "packageManager": "yarn@4.18.1", "dependencies": { "semver": "7.7.2" } }

repro.mjs:

import { readdirSync } from "node:fs";
import { createRequire } from "node:module";
import { dirname } from "node:path";

const dir = dirname(createRequire(import.meta.url).resolve("semver/package.json"));
const entry = readdirSync(dir, { recursive: true, withFileTypes: true }).find((e) => e.name === "comparator.js");
console.log({ dir, parentPath: entry.parentPath });
$ yarn install && yarn node repro.mjs
{
  dir: '/home/user/.yarn/berry/cache/semver-npm-7.7.2-dfc3bc5ec9-10c0.zip/node_modules/semver',
  parentPath: 'classes'
}

With node_modules and plain node, the same script prints parentPath: '/…/node_modules/semver/classes'.

Environment

System:
  OS: Linux 6.12 Fedora Linux 44
  CPU: (16) x64 AMD Ryzen 7 9700X 8-Core Processor
Binaries:
  Node: 26.8.2
  Yarn: 4.18.1
  npm: 12.2.0

Additional context

Found through yarn create, where a scaffolder lists its bundled templates this way and aborts on the relative paths.

Activity

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