Lahar Shah
Lahar Shah

Reputation: 7664

"EPERM: operation not permitted" on Windows with npm

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 suggestions?

Upvotes: 235

Views: 830301

Answers (30)

Balaprasad370
Balaprasad370

Reputation: 11

Once remove .vite folder from node_modules and re run the

npm run dev

or

npm start

command

Upvotes: 0

muhyidin
muhyidin

Reputation: 335

you should look what error after operation not permitted, becouse on mycase I need install python >= 3.3 and need use nodejs version <= 21

Upvotes: 0

Timothy
Timothy

Reputation: 383

I was trying to:

npx create-react-app
npm run reset-project

(reset-project is from React expo)

And this error popped up. Running as administrator didn't help either.

I made it go away by closing all everything and anything that could've been reading the directory; Explorer windows and WebStorm (which alone wasn't enough).

Somehow, something was preventing the renaming of a folder or passively monitoring files/folders and that was enough for fs to fail.

Upvotes: 0

karlos
karlos

Reputation: 990

Try npm i -g npm. NPM version 6.9 is working for me.

Upvotes: 1

vlatko606
vlatko606

Reputation: 1149

My only solution for this issue was changing the directory of the project (using Window OS). Initially was stored to C:/. when I move to C:\Users\test\Desktop started to work.

Upvotes: 2

knoxgon
knoxgon

Reputation: 1243

Executing the command by specifying the version fixed it for me.

npm install --global [email protected]

Unfortunately, neither did the restarting of the computer, executing npm i -g npm@latest or without @latest, executing npm cache clean/verify with or without respective --force argument, and even removing npm and node_modules folders and even providing access rights to the parent folder helped me.

Specifying the npm version worked.

Upvotes: 0

Salman
Salman

Reputation: 1286

I have faced the same problem and tried all the given solutions and none of them worked.

I got it solved after adding package.json as there was no package.json file available in the folder where I was trying to install a module and faced the same error.

Give it a try maybe it helps someone

npm init

npm init all (skip configurations)

Upvotes: 0

steph
steph

Reputation: 53

For me the problem come from bash terminal. I change my terminal to powershell and it's ok.

Really easy to resolve

Upvotes: 2

MegaSpaceHamlet
MegaSpaceHamlet

Reputation: 371

I was having trouble with this issue as well. Try updating Node to the latest version and then try the operation again. It may help you.

Upvotes: 0

Mohit Poddar
Mohit Poddar

Reputation: 239

npm install cross-env

Try this it worked for me.

Upvotes: 3

Jorge Mauricio
Jorge Mauricio

Reputation: 533

In my case, it had to do with the directory webpack was targeting to build the files. Somehow, the directory couldn´t be deleted, even if I would try to do it manually by windows explorer. So, you can either force delete through CMD or, as strange as it may sound, I closed my web browser that I was using to load the webpack compiled files and managed to get the directory deleted. Afterwards, I ran webpack again and worked. Maybe that was causing the directory dele block.

Upvotes: 0

Aswin Barath
Aswin Barath

Reputation: 1107

The Problem I faced (In Windows Computer)

When I was trying to install a couple of npm packages I got the following error:

npm - EPERM: operation not permitted - while npm was trying to rename a file

Here's my debug snippet for reference, if you've faced the similar problem:

The Problem I faced

After carefully checking out the answers from other users, I have created a detailed answer for the community

My Solution for the problem

Follow the mentioned steps

  1. Right-click on the project folder
  2. Go to properties -> Security Tab
  3. Select Users -> Edit
  4. In the Permission for Users section, Full control -> Give a check mark in Allow -> OK
  5. Wait for Windows security to apply the new security rules
  6. Click OK

Visualization of the steps

Change Security rules

If you follow these steps and try to install npm packages again it will work properly.

Note: It's a best practice to close and open up the command line again to experience the changes

Upvotes: 16

mohammad asghari
mohammad asghari

Reputation: 1894

Just stop react server and then install the package.

This issue occurs because when react is running (with yarn start or npm start), It is using some resources.

Upvotes: 3

Manish Paul
Manish Paul

Reputation: 551

I'd to update my npm using npm-windows-upgrade

Upvotes: 0

EliuX
EliuX

Reputation: 12655

Incredibly, this happens when you are building your project, e.g.

ng build myprojet

...and you are stood up inside the dist/myprojet, maybe withing the console. So you can easily close that console window or cd .. to prevent this from happening.

Upvotes: 0

Kamba-Bilola Ted
Kamba-Bilola Ted

Reputation: 197

Install create-react-app

I did not install create-react app. so I just run npm install -g create-react-app and the problèm was solved

Upvotes: 0

AL Mahmud
AL Mahmud

Reputation: 123

Try installing it globally first, using the command {npm install -g create-react-app}

And then, you can create your app using the command, {npx create-react-app }

worked for me

Upvotes: 2

Alamin
Alamin

Reputation: 2165

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.

Upvotes: 2

Hadayat Niazi
Hadayat Niazi

Reputation: 2480

The simpler way to solve this by entering the below command

npm config set cache C:\tmp\nodejs\npm-cache --global

Upvotes: 1

Denys Rusov
Denys Rusov

Reputation: 620

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

Upvotes: 0

Legends
Legends

Reputation: 22702

Restarting VsCode solved it for me!

Upvotes: 47

Jude Obiejesi
Jude Obiejesi

Reputation: 86

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

Upvotes: 0

Ericgit
Ericgit

Reputation: 7083

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
    

Upvotes: 4

Akhil Bisht
Akhil Bisht

Reputation: 121

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

Upvotes: 0

Saffer
Saffer

Reputation: 162

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

Upvotes: 1

factorypolaris
factorypolaris

Reputation: 2857

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.

Upvotes: 1

Sasi Kumar M
Sasi Kumar M

Reputation: 2630

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

Upvotes: 1

Kote Isaev
Kote Isaev

Reputation: 355

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.

Upvotes: 3

Thilak Raj
Thilak Raj

Reputation: 920

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

Upvotes: 0

LatentDenis
LatentDenis

Reputation: 2991

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

Upvotes: 21

Related Questions