Skip to content

rm -rf on a large node_modules directory fails on the first attempt with os error 66 (Directory not empty) and succeeds on the second attempt on macOS #19599

Closed

Description

@cotone-dev

Bug report form

  • I have done a basic search of the issue tracker to find any existing issues that are similar.
  • I have checked that my version is at least the latest stable release available via my installation method.

Describe the bug

Running rm -rf node_modules in Nushell after bun i --frozen-lockfile fails on the first attempt with nu::shell::io::directory_not_empty (Directory not empty (os error 66)), leaving node_modules intact (deleted: false), and then succeeds when run a second time (deleted: true).

  • Waiting 5–10 seconds after bun i --frozen-lockfile does not change the behavior (it does not appear to be a short-lived I/O timing race).
  • Reproduces even when starting Nushell with --no-config-file.
  • Does not occur with external /bin/rm -rf or ^rm -rf.
  • Did not reproduce on a minimal bun init project with only @types/bun in devDependencies, suggesting it may depend on directory size/depth/file count or specific entries in a larger node_modules tree.

How to reproduce

  1. Start Nushell (even with nu --no-config-file) on macOS (aarch64-apple-darwin).
  2. In a project with a package.json like the following and run bun i --frozen-lockfile:
{
  "name": "project-name",
  "version": "0.4.0",
  "private": true,
  "type": "module",
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "gen-tree": "nu scripts/generate-directory-tree.nu",
    "generate": "nuxt generate",
    "postinstall": "nuxt prepare",
    "lint": "eslint .",
    "lint:fix": "eslint . --fix",
    "prettier": "prettier --write .",
    "preview": "nuxt preview",
    "typecheck": "vue-tsc -b --noEmit"
  },
  "dependencies": {
    "@tailwindcss/vite": "4.3.5",
    "canvas-confetti": "1.9.4",
    "gsap": "3.15.1",
    "tailwindcss": "4.3.5"
  },
  "devDependencies": {
    "@commitlint/cli": "21.2.4",
    "@commitlint/config-conventional": "21.2.4",
    "@nuxt/eslint": "1.17.0",
    "@types/canvas-confetti": "1.9.0",
    "eslint": "10.15.0",
    "eslint-plugin-perfectionist": "5.14.0",
    "eslint-plugin-tailwindcss": "4.4.0",
    "nuxt": "4.6.4",
    "prettier": "3.10.1",
    "typescript": "6.0.3",
    "vue-tsc": "3.3.14",
    "wrangler": "4.165.0"
  }
}
  1. Run:
rm -rf node_modules
bun i --frozen-lockfile
rm -rfv node_modules
  1. Observe that the first rm -rfv node_modules returns deleted: false with I/O error (os error 66: Directory not empty).
  2. Run rm -rfv node_modules a second time immediately after:
rm -rfv node_modules
  1. Observe that the second run succeeds with deleted: true.

Expected behavior

The first rm -rf node_modules should remove the node_modules directory and its contents without failing with Directory not empty (os error 66).

Configuration

| key                  | value                                                                                                                                            |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| version              | 0.116.1                                                                                                                                          |
| major                | 0                                                                                                                                                |
| minor                | 116                                                                                                                                              |
| patch                | 1                                                                                                                                                |
| branch               |                                                                                                                                                  |
| commit_hash          |                                                                                                                                                  |
| build_os             | macos-aarch64                                                                                                                                    |
| build_target         | aarch64-apple-darwin                                                                                                                             |
| rust_version         | rustc 1.99.0 (b940084d7 2026-09-28) (Homebrew)                                                                                                   |
| cargo_version        | cargo 1.99.0 (5f94df478 2026-08-27) (Homebrew)                                                                                                   |
| build_time           | 2026-10-04 14:31:48 +00:00                                                                                                                       |
| build_rust_channel   | release                                                                                                                                          |
| allocator            | standard                                                                                                                                         |
| features             | dap, default, lsp, mcp, network, plugin, rustls-tls, sqlite, trash-support                                                                       |
| installed_plugins    |                                                                                                                                                  |
| experimental_options | example=false, dc-glob=false, reorder-cell-paths=true, pipefail=true, enforce-runtime-annotations=true, native-clip=false, cell-path-types=false |

Additional environment details:

  • macOS: 27.2.1 (26B131)
  • Bun: 1.4.4

Activity

  1. added
    status:needs-triage
    on Nov 19, 2026
  2. fdncred commented on Nov 19, 2026

    @fdncred
    Contributor

    I can't reproduce on 0.117.1 latest main branch. Can you try it out and see if it fixes the problems?

  3. cotone-dev commented on Nov 20, 2026

    @cotone-dev
    Author

    Thank you for checking this!

    First, I apologize for submitting the initial report on an outdated version (0.116.1) despite checking the box in the template.

    I have updated Nushell to 0.117.0 (the latest version available via Homebrew and on the GitHub Releases page) and tested it again, but the issue still reproduces with the exact same behavior.

    Regarding 0.117.1, since I couldn't find a release or tag for it, I assume you are referring to the current development state on the main branch. Building from source is a bit difficult for me, and since this isn't an urgent issue, I'd prefer to wait for the official 0.117.1 release (via Homebrew) and test it again then.

    I'll leave this issue open for now until I can verify it on 0.117.1, unless you prefer to close it earlier. Thanks again for your help!

  4. cotone-dev commented on Nov 21, 2026

    @cotone-dev
    Author

    Thanks for pointing me to the nightly releases!

    I tested this on 0.117.1-nightly.7, and it still reproduces in my original project directory:

    • Reproduces with nu --no-config-file.
    • Reproduces with both rm -rf node_modules and rm -rfv node_modules.
    • Reproduces even after completely quitting VS Code (so it does not appear to be caused by VS Code or language server extensions).
    • The first attempt fails with os error 66 (Directory not empty), and running rm -rf node_modules a second time immediately afterward succeeds.

    Error output from rm -rf node_modules:

    Error: nu::shell::io::directory_not_empty
    
      × I/O error
      ╰─▶   × Directory not empty (os error 66)
    
       ╭─[repl_entry #7:1:8]
     1 │ rm -rf node_modules
       ·        ──────┬─────
       ·              ╰── Directory not empty
       ╰────
      help: The error occurred at '/Users/<user-name>/projects/<project-name>/node_modules'
    

    Two additional findings that may help explain why you couldn't reproduce this:

    1. node_modules is partially deleted on the first attempt (rather than left completely intact as I initially assumed):
      • Before rm -rf node_modules: 41,026 entries (^find node_modules | ^wc -l)
      • Immediately after the first failed rm -rf: 12,399 entries remaining
      • ls -la node_modules after the failure shows 253 subdirectories remaining (from .cache through zip-stream), while earlier entries (such as .bin / .bun) appear to have been removed.
    2. Does not reproduce in fresh directories even with the exact same package.json and bun.lock:
      • I copied both package.json and bun.lock into /tmp/nu-rm-repro and ~/projects/nu-rm-repro, and ran bun i --frozen-lockfile.
      • ^find node_modules | ^wc -l gave the exact same count (41,026) in all three directories, yet rm -rf node_modules succeeded on the first attempt in both /tmp/nu-rm-repro and ~/projects/nu-rm-repro.
      • This suggests the issue is triggered by something specific to the original project directory (e.g., files generated/touched differently due to other project files like nuxt.config.ts, or another background process monitoring/accessing that directory).

    Please let me know if there are any specific checks or logs I can collect from the failing directory to help track this down!

    version | transpose key value | to md --pretty on nightly
    key value
    version 0.117.1-nightly.7
    major 0
    minor 117
    patch 1
    pre nightly.7
    branch nightly
    commit_hash 12717b651099e793205022c405033cb34930e56d
    build_os macos-aarch64
    build_target aarch64-apple-darwin
    rust_version rustc 1.98.1 (48a229cea 2026-09-01)
    rust_channel 1.98.1-aarch64-apple-darwin
    cargo_version cargo 1.98.1 (797e8a9bc 2026-08-05)
    build_time 2026-11-19 07:28:27 +00:00
    build_rust_channel release
    allocator standard
    features dap, default, lsp, mcp, network, plugin, rustls-tls, sqlite, static-link-openssl, trash-support
    installed_plugins
    experimental_options example=false, dc-glob=false, reorder-cell-paths=true, pipefail=true, enforce-runtime-annotations=true, native-clip=false, cell-path-types=false
  5. fdncred commented on Nov 22, 2026

    @fdncred
    Contributor

    please try #19637 and see if it helps

  6. cotone-dev commented on Nov 23, 2026

    @cotone-dev
    Author

    Thank you for the quick fix!

    I tested PR #19637 on macOS, and it completely resolves the issue for me:

    Thanks again for investigating this and putting together the fix!

  7. added
    notes:fixes
    notes:ready
    on Nov 23, 2026
  8. added theissue type on Nov 23, 2026
  9. removed
    notes:fixes
    notes:ready
    status:needs-triage
    on Nov 23, 2026
  10. added this to the v0.118.0 milestone on Nov 23, 2026
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

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions