可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
When I execute "npm install" I get this error
npm ERR! Error: EPERM: operation not permitted, rename C:\projects\******\node_modules\react-async-script' -> 'C:\projects\*******\node_modules\.react-async-script.DELETE'
- I am running the cmd as administrator
- I ran npm cache clean before
- I made sure all the other applications dont have anything related to node_modeules open
回答1:
In my situation it helped:
clean cache with
npm cache clean --force
install the latest version of npm globally as admin:
npm install -g npm@latest --force
clean cache with
npm cache clean --force
Try to install your component once again.
I hope this fix your issue. If it does not help, try to switch of antivirus program for a while and repeat.
回答2:
I got it working when tried npm install with a force option to fetch remote resources even if a local copy exists on disk. Try running
npm install --force
Updated
For some of my colleagues this solution was not working. But we tried using yarn instead of npm. It works (faster as well) without any issues all the time
yarn install [package-name]
回答3:
I was getting that same error and according to https://github.com/Medium/phantomjs/issues/19 it could be caused by your antivirus software. I disabled mine for the duration of the install and executed "npm install" on cmd as admin and it worked.
Hope this helps.
回答4:
Not package.json
, but for whatever reason, my node_modules/
had become read-only. Resetting that fixed this.
回答5:
I was getting the same thing. I didn't find this anywhere but it hit me that our VMs tend to change files to a read-only state. So I opened package.json
's file properties and deselected Read-only
in the "General" tab.
Steps
- Go to the
package.json
file.
- Right-click and select Properties.
- In the General tab, Attributes section, deselect Read-only.
- Click Apply to apply the change.
回答6:
I have had this issue multiple times only in Windows
I try these in the order usually.
- npm install --force
- Check if node_modules is set to read-only and
remove if it is
- Delete node_modules/
- Check if any editor is opened
that could have access to the root folder of the project
- Reboot :(
Usually trying npm install after one of those steps will resolve it.
回答7:
I had the same problem after updating to npm to 5.4.2, npm start giving the same error for most npm commands. Some solution suggest to run it with --no-optional:
it didn't work always.
other suggested to downgrade, i didn't want to downgrade.
I suspected that there was a problem with the installation, not sure what it is.
so i re-updated my npm:
npm i -g npm
and worked fine since then.
回答8:
In my case, it only worked when I closed VS code (the code editor) that had the workspace opened in it (maybe it was locking some files or something)
After closing the VS code & running:
npm install --force
it worked successfully
回答9:
npm was failing for me at scandir
for:
npm install -g webpack
...which might be caused by npm attempting to "modify" files that were potentially locked by other processes as mentioned here and in few other github threads. After force cleaning the cache, verifying cache, running as admin, disabling the AV, etc the solution that actually worked for me was closing any thing that might be placing a lock the files (i.e. restarting my computer).
I hope this helps someone struggling.
回答10:
This is a typical error caused by Antivirus. There is a workaround for cases like mine, where I can't disable A/V (Company Policy).
You have to change the polyfills.js
inside Npm
package:
[NODE_HOME]/node_modules/npm/node_modules/graceful_fs/polyfills.js
Look for this statement:
if (process.platform === "win32") {
Inside of this statement, there is a timeout making a retry in case of error. The problem is that in some cases, after the timeout, the file is still locked by the A/V. The solution is rip out the timeout and let this statement in loop. The change with the previous code commented:
if (platform === "win32") {
fs.rename = (function (fs$rename) { return function (from, to, cb) {
var start = Date.now()
var backoff = 0;
fs$rename(from, to, function CB (er) {
if (er
&& (er.code === "EACCES" || er.code === "EPERM")
/*&& Date.now() - start < 60000*/) {
console.log("Retrying rename file: " + from + " <> " + to)
fs$rename(from, to, CB);
/*setTimeout(function() {
fs.stat(to, function (stater, st) {
if (stater && stater.code === "ENOENT")
fs$rename(from, to, CB);
else
cb(er)
})
}, backoff)*/
if (backoff < 100)
backoff += 10;
return;
}
if (cb) cb(er)
})
}})(fs.rename)
}
回答11:
I had the same problem. The reason for the error is unsupported characters in the path to the file. Replaced the cyrillic in English - it helped.
回答12:
My answer is to do npm cache clean --force
first. Then run npm install -g npm@5.3.0
to install npm 5.3.0 version. for me, this npm version works with no trouble.
回答13:
For some, AppRoot\npm folder could be an issue. Sometimes the AppRoot folder is marked as network shared and thus Antivirus blocks the stuff. Follow below link for complete solution.
https://alastaircrabtree.com/fixing-intermittant-eperm-operation-not-permitted-on-npm-install/
I hope this helps.
回答14:
I did the following:
- Upgraded the npm to the latest version:
npm install -g
npm@6.5.0-next.0
- deleted the npm-cache folder from:
c:/users/[username]/AppData/Roaming/npm-cache
- Did cache clean :
npm cache clean --force
- Ran the
npm install
.
回答15:
Open the command prompt as administrator and navigate to the project location and then run npm install. it worked for me.
回答16:
Just delete the package folder from the path of npm global packages. then reinstall the package.
Note that the packages are globally installed in:
C:\Users\your-name\AppData\Roaming\npm\node_modules