How to fix: npm ERR! enoent ENOENT: no such file or directory, rename

I recently struggled for a while with an npm error thrown when executing npm install of some package. The error message was npm ERR! enoent ENOENT: no such file or directory, rename 'D:\\WebApp\\node_modules\\lz-string' -> 'D:\\WebApp\\node_modules.lz-string.DELETE'

Finally, I found a solution and a reason for that issue.

The error occurred when I was trying to install @testing-library/react npm package. It looked like that:

npm ERR! enoent ENOENT error in Visual Studio Code

Hotfix

If you ever get this error, the hotfix is to follow these steps:

  • delete node-modules folder
  • run command npm cache clean --force
  • run command npm install
  • install the package again with npm install your-package-name

It should all work fine after that.

If these commands still don’t solve your issue, and you use git as a source control system, you can try the unbeatable git clean -fdx command. After that, run npm install again. Beware – it removes all files not checked in to git. It may also remove your IDE settings etc., so use with care.

But it’s only a hotfix, a solution for now to unblock you.

Coldfix (solution)

The real reason for this issue in my case turned out to be related to jest. However, not to the testing library itself, but to jest extension for Visual Studio Code.

The reason for the issue is the jest tests runner working in the background. You can see that in the VS Code bottom bar:

Visual Studio Code - jest runner

The real solution is to disable jest runner when installing new packages. You can do it with a Jest: Stop Runner command in Ctrl+Shift+P:

npm ERR! enoent ENOENT fix in Visual Studio by stopping jest runner

I don’t know exactly why this is an issue. I guess jest runner is blocking some files in node-modules, so they cannot be renamed/processed. I hope it helps you too 😉

.NET full stack web developer & digital nomad
2.3 3 votes
Article Rating
Subscribe
Notify of
guest
13 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
trackback
ENOENT on npm start error. Why am I getting this error and why is it looking for "My Pictures" directory? - The web development company
2 years ago
trackback
ENOENT on npm start error. Why am I getting this error and why is it looking for "My Pictures" directory?
2 years ago
Anshultiwari
Anshultiwari
2 years ago

hey there !am facing same error issue right now in my system,and i also tried given solution but its not working for me

trackback
How To Fix Npm Install Error? The 8 Correct Answer - Ko.taphoamini.com
2 years ago

[…] + View More Here […]

trackback
Top 50 Enoent No Such File Or Directory Quick Answer
2 years ago

[…] Read More […]

trackback
Error enoent no such file or directory stat volumeicon icns
1 year ago

[…] Источник […]

test
test
1 year ago

Having done resaerch for a quite while, this finally solved the problem!
Thank you so much!

trackback
Enoent error npm install
1 year ago

[…] Источник […]

trackback
Npm err error enoent
1 year ago

[…] Источник […]

trackback
Npm err code enoent ошибка
1 year ago

[…] Источник […]

Raj Kumar
Raj Kumar
1 year ago

I’m happy to see some great articles on your site. I truly appreciate it, many thanks for sharing

Anu Sharma
Anu Sharma
1 year ago

Good information Post keep up it

trackback
Npm err code enoent ошибка — Исправление и устранение ошибок
1 year ago

[…] Источник […]