title: npm ERR! Error: EPERM: operation not permitted, unlink Windows
body: <p>I can't get npm install to work in an angular project. The install almost goes through but fails with</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>What I've tried:</p>
  
  <ul>
  <li>Running from cmd, git bash and power shell both as a regular user and as admin</li>
  <li>Deleting the node_modules folder and retrying</li>
  <li>installing nvm for Windows and installing nodejs 12.13.0 LTS (which then installs npm), then trying npm install</li>
  <li>uninstalling nvm for Windows and installing nodejs 12.13.0 LTS with the site's installer, <code>npm i -g npm</code>, <code>npm install</code></li>
  <li>excluding my workspaces dir in Windows security settings</li>
  <li><code>npm cache verify</code>, <code>npm install</code></li>
  <li><code>npm cache clean --force</code>, <code>npm install</code></li>
  </ul>
  
  <p>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.</p>
  
  <p>Update</p>
  
  <p>It looks like it might be a race condition. See <a href="https://docs.npmjs.com/common-errors" rel="nofollow noreferrer">here</a>. I'm using npm version 6.13.0.</p>
  
  <p>Another update</p>
  
  <p>I've got other problems now but Jonathan Irvin's comment helped me, in particular <a href="https://stackoverflow.com/a/51092497/5752737">this</a>. I disabled windows indexing and gave all permissions to my user.</p>