Using fs.symlinkSync( x, y, 'dir' ) to create a directory symlink is failing (EPERM: operation not permitted), while mklink /d is able to make the symlink.
Simplest example to demonstrate the issue:
C:\Users\me\AppData\Local\Temp>node
> require('fs').symlinkSync('abcdef', 'ghijkl', 'dir')
Error: EPERM: operation not permitted, symlink 'abcdef' -> 'C:\Users\me\AppData\Local\Temp\ghijkl'
at Object.fs.symlinkSync (fs.js:1014:18)
File symlinks are fine; it’s only directory symlinks that are failing. It doesn’t matter whether the target path exists or not, it fails with the same EPERM error.
Meanwhile,
C:\Users\me\AppData\Local\Temp>mklink /d ghijkl abcdef
symbolic link created for ghijkl <<===>> abcdef
Can't reproduce on master.
It was fixed in a083786c7733b5828102661a04a86884c934950a (PR: https://github.com/nodejs/node/pull/18260). cc @nodejs/lts
For an idea of the context of this: ghost-cli creates a directory symlink as part of ghost install local, and if it fails then the result is incomplete and non-functional, so it’s broken on Windows. Having WSL, I worked around that by installing ghost-cli on the Ubuntu side instead of the Windows side, but that’s a workaround rather than a fix.
The libuv upgrade will make its way into node 8 eventually. Since there is nothing to do but wait I'll go ahead and close this out.
The relevant libuv PR: https://github.com/libuv/libuv/pull/1706
This is still a problem. Any update?
@livingstonef I now have 8.11.1, and it’s fixed there. If you have an older version of Node, try upgrading. If it’s the same or newer, ensure your Windows installation is in Developer Mode, and then please verify that my “simplest example to demonstrate the issue” does in fact not work for you; if it does work, then you probably have a different issue.
fs.symlink appears to require admin privileges on Windows 10 for some reason. If anyone else runs into this, try running as admin.
@flotwig For historical and security reasons, it requires either admin privileges, or for the machine to be in developer mode and the appropriate flag set in the API call (and that flag was what was missing). But yeah, this was fixed over a year ago now.
Yeah, we're still using Node 8.9.3 (though upgrading soon!)
FWIW, I actually needed to pass type=junction to fs.symlink, that made running as admin unnecessary and made the symlinks actually work.
Most helpful comment
Yeah, we're still using Node 8.9.3 (though upgrading soon!)
FWIW, I actually needed to pass
type=junctiontofs.symlink, that made running as admin unnecessary and made the symlinks actually work.