3

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.

SebastianG
  • 5,763
  • 2
  • 24
  • 61

1 Answers1

2

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
    })
}
Edward
  • 576
  • 3
  • 5
  • I am using windows in developer mode, the issue requiring to use the junction type has been resolved with nodejs 10 and I'm running on 10.16.3 :( – SebastianG Aug 30 '19 at 11:18
  • I tested specifically for serverless and the second solution solved the problem for me (adding 'junction'). Before the change: `Error: EPERM: operation not permitted, symlink 'fs-extra' -> 'C:\...\node_modules\fs-extra'` and then after `Serverless: Starting Offline: dev/us-east-1.` On Node v10.15.0. But the Developer mode solution seems to work outside of this specific package so it needs further investigating. – Edward Aug 30 '19 at 12:13
  • I can't modify the actual package as it's a dependency, but I discussed the issue on github with the package owner and he made this change, using junction, which now works, thanks – SebastianG Aug 30 '19 at 12:56