Skip to content

[Feature]: Using node_modules as symlink throws 'Error: ENOTDIR: not a directory, rmdir' with node-modules linker #6415

@hammad2506

Description

@hammad2506

Self-service

  • I'd be willing to implement a fix

Describe the bug

Due to CI (and other reasons) we need to symlink the node_modules folder to a persistent location thus reducing the time it takes for the linking step.

Due to this, when we remove dependencies from a child workspace's package.json, which would result in an empty node_modules folder after yarn install, Yarn tries to delete the node_modules folder and throws:

Error: ENOTDIR: not a directory, rmdir '/Users/hammadbalkhi/yarn-symlinking-bug/my-workspace/node_modules'

Since node_modules is now a symlink and not a directory, Yarn fails.

To reproduce

Repo: https://github.com/hammad2506/yarn-symlinking-bug

git clone https://github.com/hammad2506/yarn-symlinking-bug.git

Let's assume the current project cwd is /Users/hammadbalkhi/yarn-symlinking-bug

Then:

  1. Create a folder inside the workspace:
    mkdir -p /Users/hammadbalkhi/yarn-symlinking-bug/my-workspace/backup
  2. Create a symlink:
ln -s /Users/hammadbalkhi/yarn-symlinking-bug/my-workspace/backup /Users/hammadbalkhi/yarn-symlinking-bug/my-workspace/node_modules
  1. Run Yarn install

You will see both yarn-symlinking-bug/my-workspace/backup & yarn-symlinking-bug/my-workspace/node_modules populated with the same contents.

  1. Now remove "react": "17" from yarn-symlinking-bug/my-workspace/package.json
  2. Run yarn install

You will see error:

Error: ENOTDIR: not a directory, rmdir '/Users/hammadbalkhi/yarn-symlinking-bug/my-workspace/node_modules'

Note: This only surfaces inside child workspaces as the topLevelWorkspace node_modules/ always contains a .yarn-state.yml file even with no dependencies, so Yarn doesn't try to nuke the node_modules folder as it's not empty.

Environment

System:
    OS: macOS 13.2.1
    CPU: (10) x64 Apple M1 Pro
  Binaries:
    Node: 18.20.4 - /private/var/folders/pz/ktqbpyd903j9d6xy5sz0lj7r0000gn/T/xfs-810b17b9/node
    Yarn: 4.3.1 - /private/var/folders/pz/ktqbpyd903j9d6xy5sz0lj7r0000gn/T/xfs-810b17b9/yarn
    npm: 10.7.0 - ~/.nvm/versions/node/v18.20.4/bin/npm

Additional context

Ensure nodeLinker: "node-modules" is being used

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions