Quick Solution for npm publish “Operation Not Permitted” Error

I recently set up Verdaccio, an open source npm private registry, as a Docker container. This is incredibly easy, using a couple of PowerShell commands:

$ImageName = 'verdaccio/verdaccio'
$ImageTag = 'latest'
docker pull ${ImageName}:${ImageTag}
docker run --interactive --tty --detach --name verdaccio --restart unless-stopped --publish 4873:4873 ${ImageName}:${ImageTag}

When I tried to publish a scoped npm package to this private registry, I received an ugly, generic-looking error message (see below).

PS C:\git\node-diskscan> npm publish
npm notice
npm notice package: @trevor/diskscan@1.0.0
npm notice === Tarball Contents ===
npm notice 263B package.json
npm notice === Tarball Details ===
npm notice name: @trevor/diskscan
npm notice version: 1.0.0
npm notice package size: 272 B
npm notice unpacked size: 263 B
npm notice shasum: 07b7b2b88bc3a840a373a870896fb081776ada44
npm notice integrity: sha512-vXsD0PO/dlQVx[…]BDEpS7SveDVpA==
npm notice total files: 1
npm notice
npm ERR! path C:\Users\TREVOR~1\AppData\Local\Temp\npm-6828-63048fb2\tmp\fromDir-2f656796\package.tgz
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall unlink
npm ERR! Error: EPERM: operation not permitted, unlink 'C:\Users\TREVOR~1\AppData\Local\Temp\npm-6828-63048fb2\tmp\fromDir-2f656796\package.tgz'
npm ERR! { [Error: EPERM: operation not permitted, unlink 'C:\Users\TREVOR~1\AppData\Local\Temp\npm-6828-63048fb2\tmp\fromDir-2f656796\package.tgz']
npm ERR! cause:
npm ERR! { Error: EPERM: operation not permitted, unlink 'C:\Users\TREVOR~1\AppData\Local\Temp\npm-6828-63048fb2\tmp\fromDir-2f656796\package.tgz'
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'unlink',
npm ERR! path:
npm ERR! 'C:\Users\TREVOR~1\AppData\Local\Temp\npm-6828-63048fb2\tmp\fromDir-2f656796\package.tgz' },
npm ERR! isOperational: true,
npm ERR! stack:
npm ERR! 'Error: EPERM: operation not permitted, unlink \'C:\Users\TREVOR~1\AppData\Local\Temp\npm-6828-63048fb2\tmp\fromDir-2f656796\package.tgz\'',
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'unlink',
npm ERR! path:
npm ERR! 'C:\Users\TREVOR~1\AppData\Local\Temp\npm-6828-63048fb2\tmp\fromDir-2f656796\package.tgz' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\TrevorSullivan\AppData\Roaming\npm-cache_logs\2019-01-09T21_06_37_651Z-debug.log

This error appears to be related to the operating system — Windows 10 Professional in my case — rejecting some kind of filesystem operation. You can see that the attempted “syscall” is “unlink” which sounds to me something like unlinking a symbolic link or junction link on-disk.

Unfortunately, the error has nothing to do with the filesystem, at least in my case. It turns out that the solution was much more simple. All I needed to do was create a new user account in the private registry and authenticate to it.

PS C:\git\node-diskscan> npm adduser --registry http://localhost:4873
Username: trevor
Password:
Email: (this IS public) myemail@email.tld
Logged in as trevor on http://localhost:4873/.

The npm error message was incredibly non-useful in identifying the root cause, but thankfully the solution was an easy one.