Skip to content

[Bug?]: fs.rm is broken with recursive option in yarn 3 pnp, node >= 20.12.0 #6247

@jwoo0122

Description

@jwoo0122

Self-service

  • I'd be willing to implement a fix

Describe the bug

When using fs.rm with recursive: true (or its sync, async version rmSync and fs/promises#rm), there's an error of TypeError [ERR_INVALID_ARG_TYPE]: The "list[2]" argument must be an instance of Buffer or Uint8Array. Received type string.

To reproduce

  1. Clone reproduction repository https://github.com/jwoo0122/yarn-3-node-20-test
  2. Run yarn node test.js

Environment

System:
    OS: macOS 14.2.1
    CPU: (10) arm64 Apple M1 Max
  Binaries:
    Node: 20.12.2 - /private/var/folders/l4/c6zfhs7d0zq4lm_fgkrlml1c0000gq/T/xfs-d0b6f4b6/node
    Yarn: 3.8.1 - /private/var/folders/l4/c6zfhs7d0zq4lm_fgkrlml1c0000gq/T/xfs-d0b6f4b6/yarn
    npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm
    bun: 1.0.27 - ~/.bun/bin/bun

Additional context

I found this doesn't happen on node 18. recursive option of fs.rm uses readdirSync, and on Node 18 we use pure node fs module but on Node 20 we use pnp patched version.

This error happens when the patched readdirSync is used internally, by converting the result from Buffer to string with NodePathFS.mapToBase. It also means that pnp patched readdirSync does not respect the encoding option, which is buffer in internal/fs/rimraf. According to Node.js Docs if the encoding option set to buffer, the result should be an array of buffer.

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