Skip to content

fs.symlink can’t create directory symlinks on Windows #18518

Description

@chris-morgan
  • Version: v8.9.4
  • Platform: Windows 10, 64-bit, build 17083 (Windows Insider Preview). In developer mode (so normal users can create symlinks).
  • Subsystem: fs

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

Activity

  1. added
    fsIssues and PRs related to file-system APIs and the fs module.
    on Feb 2, 2018
  2. added
    windowsIssues and PRs related to the Windows platform.
    on Feb 2, 2018
  3. seishun commented on Feb 2, 2018

    @seishun
    Contributor

    Can't reproduce on master.

  4. seishun commented on Feb 2, 2018

    @seishun
    Contributor

    It was fixed in a083786 (PR: #18260). cc @nodejs/lts

  5. chris-morgan commented on Feb 4, 2018

    @chris-morgan
    Author

    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.

  6. bnoordhuis commented on Feb 4, 2018

    @bnoordhuis
    Member

    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: libuv/libuv#1706

  7. livingstonef commented on Sep 4, 2018

    @livingstonef

    This is still a problem. Any update?

  8. chris-morgan commented on Sep 4, 2018

    @chris-morgan
    Author

    @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.

  9. flotwig commented on Jul 22, 2019

    @flotwig

    fs.symlink appears to require admin privileges on Windows 10 for some reason. If anyone else runs into this, try running as admin.

  10. chris-morgan commented on Jul 22, 2019

    @chris-morgan
    Author

    @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.

  11. flotwig commented on Jul 22, 2019

    @flotwig

    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.

  12. added a commit that references this issue on Apr 21, 2020
  13. OLEREO commented on Sep 23, 2021

    @OLEREO

    是的,我们仍在使用 Node 8.9.3(尽管很快就会升级!)

    FWIW,我实际上需要传递type=junction给fs.symlink,这使得以管理员身份运行变得不必要并使符号链接实际工作。

    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.

    There are still some problems. Folders are created correctly, but the files are also recognized as folders and the soft links created do not work.

  14. citkane commented on Aug 24, 2022

    @citkane

    #18518 (comment)

    FWIW, I actually needed to pass type=junction to fs.symlink, that made running as admin unnecessary and made the symlinks actually work.

    Still true in node v16.17.0

  15. bnoordhuis commented on Feb 5, 2023

    @bnoordhuis
    Member

    @IRod22 v18.x never had this issue. I suspect you're misunderstanding the discussion here.

  16. lqzhgood commented on Apr 15, 2023

    @lqzhgood

    fs.symlink api need runnning as admin. but mklink don't

    v18.16.0
    windows 11
    // need admin
    // err.message EPERM: operation not permitted, symlink 'E:\Git\xx\i' -> 'E:\Git\xx\o'
    fs.symlinkSync('i', 'o')
    
    // this is ok
    const { execSync } = require('child_process');
    execSync('mklink /J o i', { windowsHide: true });
    
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

    fsIssues and PRs related to file-system APIs and the fs module.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions