Search code examples
node.jssymlinkserverlessfs-extraserverless-plugins

'fs-extra' symlink not permitted when running as administrator and with the policy added, running mklink myself works?


I'm trying to use this plugin together with serverless to bundle my dependencies using symlinks. Under the hood it uses fs.symlink from fs-extra as follows:

async function link (target, f) {
  await fs.ensureDir(path.dirname(f))
  await fs.symlink(target, f)
    .catch(e => {
      if (e.code === 'EEXIST') {
        return
      }
      throw e
    })
}

But I get operation not permitted symlink -> even when:

  • Running as administrator
  • Local Policy updated, with the user added the ability to perform symlinks
  • mklink works from the commandline without an issue, in the same folder and all.

No idea what to do anymore around this.


Solution

  • You may need use Windows in Developer mode.

    Otherwise you'll need to specify the 'junction' type in the source code while on Windows.

    async function link (target, f) {
      await fs.ensureDir(path.dirname(f))
      await fs.symlink(target, f, 'junction')
        .catch(e => {
          if (e.code === 'EEXIST') {
            return
          }
          throw e
        })
    }