This problem is due to the way Cygwin handles symbolic links during recursive copying.
The problem sequence
- During recursive directory copying,
cp
traverses the directory structure in a specific order - When it finds a symbolic link, it attempts to recreate that link in the destination
- If the link points to a relative path (like
../some-package/bin.js
), Cygwin checks if that target exists in the destination directory structure - In
winsymlinks:nativestrict
mode, Cygwin performs strict security checks on the target path - If the target file/directory hasn't been copied yet (because of the traversal order), these checks fail
- The error "cannot create symbolic link: No such file or directory" is generated
Symlink modes in Cygwin
Cygwin's behavior with symbolic links is controlled by the CYGWIN
environment variable:
Mode | Description | Behavior with symbolic links |
---|---|---|
Default (unset) | Uses Cygwin's emulated symlinks | Creates special files that only Cygwin recognizes as symlinks |
winsymlinks:native |
Uses native Windows NTFS symbolic links | Creates proper Windows symlinks, less strict about target existence |
winsymlinks:nativestrict |
Uses native Windows NTFS symlinks with strict security checks | Creates Windows symlinks but strictly verifies target paths |
A comparison of symbolic link types in Windows and Cygwin
Solution
Why this works
The winsymlinks:native
mode still creates proper Windows symbolic links but skips some of the strict security checks that would otherwise fail when targets don't yet exist in the destination directory. This allows the copy operation to complete successfully even with complex directory structures.
Native Windows symlinks will be properly recognized by both Windows and Cygwin tools, preserving the integrity of your directory structure.