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:

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
        })
    }