deno
7aceb221 - fix(install): handle pre-existing node_modules symlink on Windows (#34659)

Commit
172 days ago
fix(install): handle pre-existing node_modules symlink on Windows (#34659) Fixes #30723. On Windows, reusing a `node_modules` directory across runs (for example one restored from a CI cache) can leave a stale directory symlink or junction behind. When the installer tries to recreate that link it first removes the previous entry with `remove_dir_all`, but on Windows that call can fail to remove a directory symlink or junction (notably a dangling one). The stale entry is then left in place, so both the symlink attempt and the junction fallback fail with `ERROR_ALREADY_EXISTS` (os error 183) and the install aborts with: ``` Warning Unexpected error symlinking node_modules: Cannot create a file when that file already exists. (os error 183) error: Creating junction in node_modules folder ``` This worked on Deno 2.4.x and regressed in 2.5.0. The intermittent nature of the failure matches a removal that only sometimes leaves the link behind. This removes the previous entry the Windows-correct way: a directory symlink or junction is removed with `RemoveDirectory`, falling back to `DeleteFile` for a file symlink and then to a recursive removal for a real directory. The same removal logic already lives in `cleanup_unused_packages`, so this brings the create path in line with it. As a safety net, symlink and junction creation now retry once after clearing a conflicting entry if creation still reports `AlreadyExists`.
Author
Parents
Loading