Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
hammad2506 opened this issue Jul 25, 2024 · 0 comments · Fixed by #6416
Assignees
Labels
enhancement New feature or request node-modules

Comments

@hammad2506
Copy link

hammad2506 commented Jul 25, 2024

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

@hammad2506 hammad2506 added the bug Something isn't working label Jul 25, 2024
@larixer larixer added node-modules upholded Real issues without formal reproduction labels Jul 25, 2024
@larixer larixer self-assigned this Jul 25, 2024
@larixer larixer added enhancement New feature or request and removed upholded Real issues without formal reproduction bug Something isn't working labels Jul 26, 2024
@larixer larixer changed the title [Bug]: Using node_modules as symlink throws 'Error: ENOTDIR: not a directory, rmdir' with node-modules linker [Feature]: Using node_modules as symlink throws 'Error: ENOTDIR: not a directory, rmdir' with node-modules linker Jul 26, 2024
github-merge-queue bot pushed a commit that referenced this issue Aug 11, 2024
…nks (#6416)

## What's the problem this PR addresses?

<!-- Describe the rationale of your PR. -->
<!-- Link all issues that it closes. (Closes/Resolves #xxxx.) -->

Fixes: #6415 

## How did you fix it?

<!-- A detailed description of your implementation. -->

Now the `node-modules` linker do not try to delete or recreate
`<any_workspace>/node_modules` directories if they are symlinks and the
underlying dependencies were removed or newly added.

## Checklist

<!--- Don't worry if you miss something, chores are automatically
tested. -->
<!--- This checklist exists to help you remember doing the chores when
you submit a PR. -->
<!--- Put an `x` in all the boxes that apply. -->
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).

<!-- See
https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released
for more details. -->
<!-- Check with `yarn version check` and fix with `yarn version check
-i` -->
- [x] I have set the packages that need to be released for my changes to
be effective.

<!-- The "Testing chores" workflow validates that your PR follows our
guidelines. -->
<!-- If it doesn't pass, click on it to see details as to what your PR
might be missing. -->
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request node-modules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants