npm install fails on Windows 10: ENOENT 4058 operation not permitted, rename

Introduction

Recently, I’ve faced different issues when tryng npm install in some of the project I’ve been working with.

Environment

  • Windows 10 (OS Build 15063.413)
  • Node version: 8.1.2
  • NPM version: 5.0.3

Every time I tried npm install or install a isolated package I got errors like this one: ENOENT 4058

Problem

1
2
3
4
5
6
7
_npm ERR! path \GitHub\react-typescript-webpack2-cssModules-postCSS\node_modules\ts-loader
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename 'D:\GitHub\react-typescript-webpack2-cssModules-postCSS\node_m
odules\ts-loader' -> '\GitHub\react-typescript-webpack2-cssModules-postCSS\node_modules\.ts-loader.DELETE'
npm ERR! enoent This is related to npm not being able to find a file._

Solution

The solution for my specific scenario was:

1. Close VS Code 2. Remove package-lock.json, node_modules and npm cache

1
2
3
4
# Windows
del package-lock.json
rd /s /q node_modules
npm cache clear --force

1
2
3
4
# macOs
rm package-lock.json
rm -rf node_modules/
npm cache clear --force

3. Retry npm i

Read more…

If you still have this problem, read this: https://github.com/npm/npm/issues/10826

 

Author: José Quinto
Link: https://blog.josequinto.com/2017/06/23/npm-install-fails-on-windows-10-enoent-4058-operation-not-permitted-rename/
Copyright Notice: All articles in this blog are licensed under CC BY-SA 4.0 unless stating additionally.