npm ERR! Error: EPERM: operation not permitted, unlink Windows

I can't get npm install to work in an angular project. The install almost goes through but fails with

npm ERR! code EPERM
npm ERR! syscall unlink
npm ERR! path C:\workspaces\my-project\my-module\node_modules\.staging\typescript-d1902bf5\lib\typescriptServices.js
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, unlink 'C:\workspaces\my-project\my-module\node_modules\.staging\typescript-d1902bf5\lib\typescriptServices.js'
npm ERR!  [OperationalError: EPERM: operation not permitted, unlink 'C:\workspaces\my-project\my-module\node_modules\.staging\typescript-d1902bf5\lib\typescriptServices.js'] {
npm ERR!   cause: [Error: EPERM: operation not permitted, unlink 'C:\workspaces\my-project\my-module\node_modules\.staging\typescript-d1902bf5\lib\typescriptServices.js'] {
npm ERR!     errno: -4048,
npm ERR!     code: 'EPERM',
npm ERR!     syscall: 'unlink',
npm ERR!     path: 'C:\\workspaces\\my-project\my-module\\node_modules\\.staging\\typescript-d1902bf5\\lib\\typescriptServices.js'
npm ERR!   },
npm ERR!   stack: "Error: EPERM: operation not permitted, unlink 'C:\\workspaces\\my-project\my-module\\node_modules\\.staging\\typescript-d1902bf5\\lib\\typescriptServices.js'",
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'unlink',
npm ERR!   path: 'C:\\workspaces\\my-project\my-module\\node_modules\\.staging\\typescript-d1902bf5\\lib\\typescriptServices.js',
npm ERR!   parent: 'my-module'
npm ERR! }
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.

What I've tried:

  • Running from cmd, git bash and power shell both as a regular user and as admin
  • Deleting the node_modules folder and retrying
  • installing nvm for Windows and installing nodejs 12.13.0 LTS (which then installs npm), then trying npm install
  • uninstalling nvm for Windows and installing nodejs 12.13.0 LTS with the site's installer, npm i -g npm, npm install
  • excluding my workspaces dir in Windows security settings
  • npm cache verify, npm install
  • npm cache clean --force, npm install

Can anyone suggest something I may not have thought of? Unfortunately I can't post my package.json or .npmrc as the repository I'm using is not public but from the looks of the error it should be irrelevant.

Update

It looks like it might be a race condition. See here. I'm using npm version 6.13.0.

Another update

I've got other problems now but Jonathan Irvin's comment helped me, in particular this. I disabled windows indexing and gave all permissions to my user.

1 answer

  • answered 2019-11-08 14:53 Jose Barranco

    try npm unlink on the root directory of the project.