I’m having trouble with npm on my Windows computer. I tried to change the prefix setting but now I can’t run any npm commands. Every time I try, I get an error message saying the operation isn’t allowed. It’s trying to make a folder in my Git directory but it can’t.
I’ve already tried deleting some config files, but that didn’t fix it. Here’s what I did:
npm config set prefix C:/npm-global
And now when I run npm commands, I see this:
Error: EPERM: operation not permitted, mkdir 'C:/Program Files/Git/npm-global'
I’m not sure what to do next. Has anyone run into this before? How can I get npm working again? Thanks for any help!
I faced a similar problem when npm tried to access protected directories. In my case, I discovered that the custom prefix had inadvertently pointed npm to a directory within the Git installation. I solved this by opening Command Prompt as an administrator and running the command to delete the current prefix setting. I then reset the prefix to a location within my user directory with the correct command and ensured that the new path was included in my system’s PATH variable.
After restarting the command prompt, the permission errors were resolved.
I’ve been there, and it’s frustrating when npm suddenly stops working. In my experience, the issue often stems from Windows permissions and how npm interacts with system directories. Here’s what worked for me:
First, I completely uninstalled npm and Node.js from my system. Then, I reinstalled Node.js, which comes bundled with npm. This fresh install usually resolves permission conflicts.
After reinstalling, I set up a new global directory in my user folder:
npm config set prefix C:\Users\YourUsername\AppData\Roaming\npm
This keeps npm away from system directories and reduces permission issues.
Lastly, I added this new directory to my PATH environment variable. After a system restart, npm commands worked smoothly without any permission errors.
It takes a bit of time, but it’s a reliable fix that’s saved me countless headaches.
hey, i had the same issue! try running cmd as admin and use this:
npm config delete prefix
npm config set prefix %APPDATA%\npm
then add %APPDATA%\npm to your PATH. restart cmd and it should work. good luck!