141

I ran

npm config set prefix /usr/local

After running that command, When trying to run any npm commands on Windows OS I keep getting the below.

Error: EPERM: operation not permitted, mkdir 'C:\Program Files (x86)\Git\local'
at Error (native)

Have deleted all files from

C:\Users\<your username>\.config\configstore\

It did not work.

Any suggestion ?

Lahar Shah
  • 5,402
  • 4
  • 20
  • 37
  • 37
    Running `npm cache clean --force` solved the issue for me. – Nuhman Dec 06 '17 at 08:50
  • 1
    Running npm cache clean --force for two times worked for me. – VIshal Jain Jul 09 '19 at 10:17
  • 1
    Did you run it in the `cmd.exe` "terminal" (command prompt) or from the `GitBash` terminal? For me, it failed when I ran it in `GitBash` but worked fine when I ran it in `cmd`. – Henke Jan 22 '21 at 17:08
  • 1
    Today I got EPERM even in `cmd.exe`. But I ran the following command standing in `C:\Program Files\nodejs`, and it seems to have worked: `npm cache clean --force && npm install --force --global`. I also added `C:\Program Files\nodejs\node_modules` to my system `PATH` environment variable. – Henke Jan 23 '21 at 16:00
  • 1
    Screen-dump: https://i.imgur.com/VLFS7lG.png. But it might be a good idea to try https://stackoverflow.com/a/44014485 first. – Henke Jan 23 '21 at 16:54

37 Answers37

131

Running this command was my mistake.

npm config set prefix /usr/local

Path /usr/local is not for windows. This command changed the prefix variable at 'C:\Program Files (x86)\Git\local'

To access and make a change to this directory I need to run my cmd as administrator.

So I did:

  1. Run cmd as administrator
  2. Run npm config edit (You will get notepad editor)
  3. Change prefix variable to C:\Users\<User Name>\AppData\Roaming\npm

Then npm start works in a normal console.

Mathias Lykkegaard Lorenzen
  • 13,158
  • 19
  • 85
  • 163
Lahar Shah
  • 5,402
  • 4
  • 20
  • 37
43

This is occurring because windows is not giving permission to the user to create a folder inside system drive. To solve this:

Right Click

The Folder > Properties > Security Tab

Click on Edit to change Permissions > Select the user and give Full Control to that user.

mikemaccana
  • 81,787
  • 73
  • 317
  • 396
RatneZ
  • 704
  • 6
  • 8
  • 2
    Add some explanation with answer for how this answer help OP in fixing current issue – ρяσѕρєя K Jun 20 '16 at 06:00
  • 1
    Granting the user access to change system folders is not a good idea, especially when this can be easily fixed by changing the prefix to a folder in the user's home directory. – atomic77 Mar 23 '18 at 21:07
  • 1
    this will not work with a company laptop where you are not the system admin. – schlingel Jan 17 '19 at 11:56
  • In our case we have full control but folder was hidden. If you have already full control then check hidden option of the folder. – Blast May 03 '21 at 08:21
38

Sometimes, all that's required is to stop the dev server before installing/updating packages.

Ezra Obiwale
  • 1,430
  • 11
  • 13
37

I solved the problem by changing windows user access for the project folder:

Here is a screenshot: http://prntscr.com/djdn0g

enter image description here

Naseh Badalov
  • 264
  • 1
  • 6
lito
  • 2,792
  • 9
  • 40
  • 68
26

I recently had the same problem when I upgraded to the new version, the only solution was to do the downgraded

To uninstall:

npm uninstall npm -g

Install the previous version:

npm install npm@5.3 -g

Try update the version in another moment.

Leonardo Oliveira
  • 1,289
  • 1
  • 12
  • 14
16

Restarting VsCode solved it for me!

Legends
  • 16,460
  • 9
  • 75
  • 108
15

I use Windows 10. I started the CMD as administrator, and it solved the problem.

Find CMD, right click, and click open as administrator.

nicovank
  • 3,021
  • 1
  • 18
  • 40
DIANGELISJ
  • 639
  • 6
  • 4
  • @EtienneGautier That's... simply not true at all. What's your proposed solution for modifying system files? If there's any way to do it _other than_ with "administrator permissions" then there's something seriously wrong with the OS's security. – Clonkex Jul 20 '20 at 00:59
  • Hey @Clonkex, I was assuming that the context was NPM's one (according to the question). Still my comment is not relevant, I'm deleting it. Thank you for your feedback. – Etienne Gautier Jul 20 '20 at 16:25
  • @EtienneGautier Ah fair enough. – Clonkex Jul 20 '20 at 22:58
13

In my case, I was facing this error because my directory and its file were opened in my editor (VS code) while I was running npm install. I solved the issue by closing my editor and running npm install through the command line.

Shashank Rawat
  • 1,151
  • 11
  • 14
12

I had an outdated version of npm. I ran a series of commands to resolve this issue:

npm cache clean --force

Then:

npm install -g npm@latest --force

Then (once again):

npm cache clean --force

And finally was able to run this (installing Angular project) without the errors I was seeing regarding EPERM:

ng new myProject
LatentDenis
  • 2,473
  • 9
  • 41
  • 85
11

I had the same problem, after updating npm. Solved it by re-installing latest npm again with:

npm i -g npm

but this time with cmd running in administrating mode.

i did all this because i suspected there was an issue with the update, mostly some missing files.

Web Steps
  • 318
  • 2
  • 10
9

I had the same problem when I tried to install the npm package AVA. The solution for me was to delete the node_modules folder and force-clean the npm cache:

rm -rf node_modules
npm cache clean --force

I could then install the npm package without a problem.

Liran H
  • 5,181
  • 4
  • 30
  • 39
  • Yes, I somehow was having node_modules folders in the current working directory. It was throwing that exception when I tried to run angular cli commands 'ng new..'. Deleting node_modules folders helped. – Ashokan Sivapragasam Mar 07 '19 at 10:38
8

for me it was an issue of altering existing folders in node_module, so i nuked the whole folder and run npm install again. it works with no errors after that

Sonic Soul
  • 21,043
  • 31
  • 118
  • 190
4

Just run cmd as admin. delete old node_modules folder and run npm install again.

Rahul Khunt
  • 594
  • 4
  • 5
  • 1
    npm install should work without starting CMD as admin. It is not working on normal cmd(non admin) is also an issue. – Lahar Shah Dec 11 '17 at 05:52
4

Simplest way

Hope I am not too late for this post but recently even I too got hit by this issue. And also I had no admin rights on my laptop.

Here is the simplest way I fixed the bug.

  1. Locate the file name .npmrc (it will be in C:\Users\<user name>\.npmrc)
  2. Open it and change the path of prefix= to prefix=C:\Users\<user name>\AppData\Roaming\npm

hope it will be helpful..

Rishabh Jain
  • 136
  • 8
3

If you getting this error in an IDE's terminal/commands prompt, try delete node_modules, close IDE, and run the npm install command again. The time when IDE started but still not completed its analysis of node_modules tree is a tricky moment, when packages installation may fail because IDE still scanning node_modules contents.

Kote Isaev
  • 133
  • 8
3

This error is caused by different problems try the below one of them will work for you!

  • try to run npm as Administrator

  • Run cmd as administrator npm config edit (You will get notepad editor) Change Prefix variable to C:\Users\<User Name>\AppData\Roaming\npm

  • The errors went after I disabled my anti-virus (Avast)

  • Sometimes a simple cache clear like the below would fix it.

     npm cache clear
    
Ericgit
  • 2,624
  • 2
  • 22
  • 34
2

Find this command npm cache clean as a solution to those error in quick and simple way!

Hanny Setiawan
  • 492
  • 3
  • 13
2

Happened to me since the folder/file was locked by another process. Used a tool (LockHunter) to terminate that process and it started working again (possible reason).

Hummus
  • 429
  • 1
  • 5
  • 16
2

I was running create-react-app server. Simply stopped the server and everything worked just fine.

Saffer
  • 119
  • 7
  • 1
    This solved my problem! I think you should try this first before trying the others. Since other answers require more effort. – Irfandy Jip May 31 '20 at 10:37
1

I had the same issue, as I was using my company LAN. And I just ran cmd.exe npm and I was able to execute my other commands without any error after that.

C:\Users\586656>cmd.exe npm
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

Just sharing this, as it may help other folks who try to do this in their office LAN. Thank you.

Sibeesh Venu
  • 12,177
  • 5
  • 67
  • 98
1

I updated my node version to 8.9.4 and ran the necessary install command again from administrator command prompt. It worked for me!

Rahul Sharma
  • 229
  • 3
  • 8
1

A reboot of my laptop and then

npm install

worked for me!

Chau Nguyen
  • 816
  • 7
  • 11
1

Try npm i -g npm . NPM version 6.9 is work to me.

karlos
  • 388
  • 1
  • 13
1

Windows 10,

Running the IDE (in my case IntelliJ) in administrator mode and executing npm install does resolves the problem.

If no IDE then run CMD in administrator mode and try executing npm install

Sasi Kumar M
  • 1,484
  • 1
  • 15
  • 20
0

Try to install npm package by running CMD as Administrator. you can headover to broad discussion on this bug at npm install throwing error EPERM.

Kiran Maniya
  • 5,637
  • 4
  • 34
  • 53
0

Running npm commands in Windows Powershell solved my issue.

Sai Prasad
  • 93
  • 9
0

Same to me, My solution was close Android studio, AVD Manager, Visual Studio and reinstall. I executed this command to update my expo cli:

npm install -g expo-cli
Loitd
  • 301
  • 2
  • 3
0

Apparently anti-virus software can also cause this error. In my case I had Windows Security's Ransomware Protection protecting my user folders which caused this error.

orrd
  • 7,544
  • 3
  • 33
  • 28
0

For me, It was an issue with the .npmrc file. Which is present in C:\Users\myname.npmrc Somehow the content of .npmrc file got changed. I have changed the content by comparing with my colleagues laptop. So it solved.

For reference, I am adding the content of .npmrc file too

 ;;;;
 ;npm userconfig file
 ;this is a simple ini-formatted file
 ;lines that start with semi-colons are comments.
 ;read `npm help config` for help on the various options
 ;;;;

 //registry.npmjs.org/:_authToken=95632bcf-3056-4538-b57d-38426736e3a0
 scope=true
 @true:registry=https://registry.npmjs.org/

 ;;;;
 ;all options with default values
 ;;;;
 ;access=null

 ;allow-same-version=false

 ;always-auth=false

 ;also=null

 ;audit=true

 ;audit-level=low

 ;auth-type=legacy

 ;before=null

 ;bin-links=true

 ;browser=null

 ;ca=null

 ;cafile=undefined

 ;cache=C:\Users\myname\AppData\Roaming\npm-cache

 ;cache-lock-stale=60000

 ;cache-lock-retries=10

 ;cache-lock-wait=10000

 ;cache-max=null

 ;cache-min=10

 ;cert=null

 ;cidr=null

 ;color=true

 ;depth=null

 ;description=true

 ;dev=false

 ;dry-run=false

 ;editor=notepad.exe

 ;engine-strict=false

 ;force=false

 ;fetch-retries=2

 ;fetch-retry-factor=10

 ;fetch-retry-mintimeout=10000

 ;fetch-retry-maxtimeout=60000

 ;git=git

 ;git-tag-version=true

 ;commit-hooks=true

 ;global=false

 ;globalconfig=C:\Users\myname\AppData\Roaming\npm\etc\npmrc

 ;global-style=false

 ;group=0

 ;ham-it-up=false

 ;heading=npm

 ;if-present=false

 ;ignore-prepublish=false

 ;ignore-scripts=false

 ;init-module=C:\Users\myname\.npm-init.js

 ;init-author-name=

 ;init-author-email=

 ;init-author-url=

 ;init-version=1.0.0

 ;init-license=ISC

 ;json=false

 ;key=null

 ;legacy-bundling=false

 ;link=false

 ;local-address=undefined

 ;loglevel=notice

 ;logs-max=10

 ;long=false

 ;maxsockets=50

 ;message=%s

 ;metrics-registry=null

 ;node-options=null

 ;node-version=10.15.2

 ;offline=false

 ;onload-script=null

 ;only=null

 ;optional=true

 ;otp=null

 ;package-lock=true

 ;package-lock-only=false

 ;parseable=false

 ;prefer-offline=false

 ;prefer-online=false

 ;prefix=C:\Program Files\nodejs

 ;preid=

 ;production=false

 ;progress=true

 ;proxy=null

 ;https-proxy=null

 ;noproxy=null

 ;user-agent=npm/{npm-version} node/{node-version} {platform} {arch}

 ;read-only=false

 ;rebuild-bundle=true

 ;registry=https://registry.npmjs.org/

 ;rollback=true

 ;save=true

 ;save-bundle=false

 ;save-dev=false

 ;save-exact=false

 ;save-optional=false

 ;save-prefix=^

 ;save-prod=false

 ;scope=

 ;script-shell=null

 ;scripts-prepend-node-path=warn-only

 ;searchopts=

 ;searchexclude=null

 ;searchlimit=20

 ;searchstaleness=900

 ;send-metrics=false

 ;shell=C:\windows\system32\cmd.exe

 ;shrinkwrap=true

 ;sign-git-commit=false

 ;sign-git-tag=false

 ;sso-poll-frequency=500

 ;sso-type=oauth

 ;strict-ssl=true

 ;tag=latest

 ;tag-version-prefix=v

 ;timing=false

 ;tmp=C:\Users\myname\AppData\Local\Temp

 ;unicode=false

 ;unsafe-perm=true

 ;update-notifier=true

 ;usage=false

 ;user=0

 ;userconfig=C:\Users\myname\.npmrc

 ;umask=0

 ;version=false

 ;versions=false

 ;viewer=browser

 ;_exit=true

 ;globalignorefile=C:\Users\myname\AppData\Roaming\npm\etc\npmignore
Thilak Raj
  • 828
  • 1
  • 9
  • 22
0

For those trying to update config

If having trouble updating your npm config, try instead running using the -g flag. This solved the issue on Win 10 for me after trying everything else.

npm config edit -g

I am able to update the config and changes are reflected everywhere. This may be due to running npm in an organizational scope.

factorypolaris
  • 1,833
  • 7
  • 11
0

npm install cross-env Try this it worked for me.

0

After trying everything and nothing works. Moving my working project folder to diffrent destination worked for me.

0

Likely when you experience this issue, it is possible is a permission issue on your PC. Going to the PC properties and granting which ever account you use on your PC full control will solve it.

Again command /usr/local doesn't work on windows

0

If cleaning the cache(npm cache clean --force) doesn't help you just delete manually the folder C:\Users\%USER_NAME%\AppData\Roaming\npm-cacheand and reinstall NodeJS

Denys Rusov
  • 394
  • 3
  • 5
0

The simpler way to solve this by entering the below command

npm config set cache C:\tmp\nodejs\npm-cache --global
HadiNiazi
  • 168
  • 1
  • 1
  • 9
0

At least I just solved my problem in this way:

  1. Search cmd
  2. Then run as administrator
  3. Then npm i -g expo-cli or npm config set prefix /usr/local

I just solved my problem.

Alamin
  • 575
  • 1
  • 13
-7

If using company LAN, disconnect try with other internet network.

Milan
  • 7
  • 4
  • 1
    Please first read the question clearly and understand what the problem is, then try to answer with descriptive and related format of how and why your answer can be a possible solution. Hope it helps ! – Fahim Uddin Apr 03 '20 at 15:03