Introduction
On this Byte we’ll strive that can assist you perceive and repair a standard npm error – “npm ERR! code ENOTEMPTY”. If you happen to’ve been working with Node.js and npm, chances are high you’ve got encountered this error sooner or later. However don’t fret, we’ll do our greatest to demystify it for you.
What’s “npm ERR! code ENOTEMPTY”?
“npm ERR! code ENOTEMPTY” is an error message that npm, the Node.js package deal supervisor, throws when it encounters a non-empty listing whereas trying to put in a package deal. The “ENOTEMPTY” a part of the error message is definitely an ordinary POSIX error code, which stands for “Error, Not Empty”. In easier phrases, npm is making an attempt to inform us that it will probably’t carry out the operation as a result of the goal listing just isn’t empty.
Notice: The POSIX normal defines a set of working system interfaces to make sure compatibility between totally different programs. ‘ENOTEMPTY’ is likely one of the many error codes outlined on this normal.
Widespread Causes of the Error
The “npm ERR! code ENOTEMPTY” error usually happens when npm tries to interchange a listing with a file throughout the set up course of, however finds that the listing just isn’t empty. This could possibly be as a result of a number of causes:
- Concurrent installations: If you happen to’re operating a number of npm installations concurrently, they might intrude with one another.
- Earlier set up leftovers: If a earlier npm set up was interrupted or did not full efficiently, it might have left some information behind within the listing.
- Guide modifications: If you happen to’ve manually added information to the node_modules listing, npm would possibly throw this error when it tries to replace or exchange a package deal.
The unlucky reality about errors like these is that you just may not
The right way to Repair “npm ERR! code ENOTEMPTY”
Now that we all know what causes the error, let’s take a look at tips on how to remedy it.
-
Delete node_modules: There could also be a problem along with your node_modules listing that’s stopping npm from putting in a brand new module there. This could possibly be a corrupt state attributable to a earlier failed set up, manually altering contents of the listing, or one thing else. That is usually the answer that works for most individuals. Delete the listing with:
$ rm -r node_modules
To be secure, you could possibly even delete the
package-lock.json
file to make sure you get a full re-install. -
Clear the npm cache: The npm cache is sort of a storage for downloaded packages. Generally, this cache can develop into corrupted, resulting in errors. You possibly can clear the cache utilizing the next command:
$ npm cache clear --force
-
Delete particular package deal: If you happen to’re
npm set up
takes a really very long time and also you’d slightly maintain the precise downside, you may strive simply deleting the problematic package deal. For instance:$ rm -r node_modules/my_module
This manner you may take away solely the issue after which solely reinstall that package deal, rushing up the method.
Comparable Errors
Now, you is likely to be questioning, what if I encounter an analogous error however not precisely the npm ERR! code ENOTEMPTY
? Effectively, npm has a variety of errors that it will probably throw, and whereas all of them have totally different causes, a lot of them might be mounted utilizing comparable options.
As an example, npm ERR! code EEXIST
is one other widespread error that happens when a file that npm wants to put in writing already exists. Just like the earlier options, this may usually be mounted by deleting the offending file and operating npm set up
once more.
$ rm -rf offending-file
$ npm set up
One other error, npm ERR! code EACCES
, happens when npm would not have the mandatory permissions to put in writing to a file or listing. You possibly can usually repair this by altering the permissions of the file or listing with the chmod
command.
$ chmod 755 offending-directory
$ npm set up
Conclusion
On this Byte, we have coated a number of widespread npm errors, particularly the npm ERR! code ENOTEMPTY
error. We have discovered about its widespread causes and tips on how to remedy it, in addition to different comparable errors and their options, broadening our understanding of npm and its quirks.