Self-service
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:
- Create a folder inside the workspace:
mkdir -p /Users/hammadbalkhi/yarn-symlinking-bug/my-workspace/backup
- Create a symlink:
ln -s /Users/hammadbalkhi/yarn-symlinking-bug/my-workspace/backup /Users/hammadbalkhi/yarn-symlinking-bug/my-workspace/node_modules
- 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.
- Now remove
"react": "17" from yarn-symlinking-bug/my-workspace/package.json
- 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
Self-service
Describe the bug
Due to CI (and other reasons) we need to symlink the
node_modulesfolder 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 emptynode_modulesfolder afteryarn install, Yarn tries to delete the node_modules folder and throws:Since
node_modulesis 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.gitLet's assume the current project cwd is
/Users/hammadbalkhi/yarn-symlinking-bugThen:
mkdir -p /Users/hammadbalkhi/yarn-symlinking-bug/my-workspace/backupYarn installYou will see both
yarn-symlinking-bug/my-workspace/backup&yarn-symlinking-bug/my-workspace/node_modulespopulated with the same contents."react": "17"fromyarn-symlinking-bug/my-workspace/package.jsonyarn installYou will see error:
Note: This only surfaces inside child workspaces as the
topLevelWorkspacenode_modules/always contains a.yarn-state.ymlfile even with no dependencies, so Yarn doesn't try to nuke thenode_modulesfolder 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/npmAdditional context
Ensure
nodeLinker: "node-modules"is being used