Angular-CLI ng new: “Error: EPERM: operation not p

2019-05-07 02:56发布

问题:

I am trying to use Angular-CLI to install a new Angular2 app, but keep running into the following issue:

ng new payment-calc-app

After "Installing packages for tooling via npm", I get the following Error codes:

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm ERR! path C:\Users\jweston\Documents\Apps\payment-calc-app\node_modules\.staging\rxjs-ccea9159
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall rename
npm ERR! Error: EPERM: operation not permitted, rename 'C:\Users\jweston\Documents\Apps\payment-calc-app\node_modules\.staging\rxjs-ccea9159' -> 'C:\Users\jweston\Documents\Apps\payment-calc-app\node_modules\rxjs'
npm ERR!     at destStatted (C:\Users\jweston\AppData\Roaming\npm\node_modules\npm\lib\install\action\finalize.js:29:7)
npm ERR!     at C:\Users\jweston\AppData\Roaming\npm\node_modules\npm\node_modules\graceful-fs\polyfills.js:284:29
npm ERR!     at FSReqWrap.oncomplete (fs.js:123:15)
npm ERR!
npm ERR! Error: EPERM: operation not permitted, rename 'C:\Users\jweston\Documents\Apps\payment-calc-app\node_modules\.staging\rxjs-ccea9159' -> 'C:\Users\jweston\Documents\Apps\payment-calc-app\node_modules\rxjs'
npm ERR!     at Error (native)
npm ERR!  { Error: EPERM: operation not permitted, rename 'C:\Users\jweston\Documents\Apps\payment-calc-app\node_modules\.staging\rxjs-ccea9159' -> 'C:\Users\jweston\Documents\Apps\payment-calc-app\node_modules\rxjs'
npm ERR!     at destStatted (C:\Users\jweston\AppData\Roaming\npm\node_modules\npm\lib\install\action\finalize.js:29:7)
npm ERR!     at C:\Users\jweston\AppData\Roaming\npm\node_modules\npm\node_modules\graceful-fs\polyfills.js:284:29
npm ERR!     at FSReqWrap.oncomplete (fs.js:123:15)
npm ERR!
npm ERR! Error: EPERM: operation not permitted, rename 'C:\Users\jweston\Documents\Apps\payment-calc-app\node_modules\.staging\rxjs-ccea9159' -> 'C:\Users\jweston\Documents\Apps\payment-calc-app\node_modules\rxjs'
npm ERR!     at Error (native) parent: 'payment-calc-app' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\jweston\AppData\Roaming\npm-cache\_logs\2017-03-23T19_17_36_190Z-debug.log

Package install failed, see above.

I've tried npm clean cache and running Command Prompt as an Administrator (I'm on Windows) to no avail.

Oddly enough, when I go to try to delete the folders that the failed installation created, Windows prevents me from deleting them, saying I need to be an Administrator to delete them, even though I am an administrator. I need to go into each individual folder and delete each individual file one at a time.

回答1:

In my case the problem was that I had another command prompt with 'ng serve' running, I stopped the process and the creation completed successfully



回答2:

  • Use command: npm install -g @angular/cli --no-optional
  • Close current angular project folder (in this case payment-calc-app)
  • Give parent folder read & write permission & archive permission (right click parent folder & give permissions to folder & child
    folders)
    • Open NodeJs command prompt in administrator mode
    • Run command ng new payment-calc-app


回答3:

Dear angular 2 coders for survival - this error was pain in the butt, did not resolve with npm cache clean, or restart or other my known methods... Just uninstall previous node version and INSTALL new current version @ https://nodejs.org/en/download/current/ - this resolved the error on my machine..so good luck!



回答4:

I had this same issue. I solved it by rolling back to NodeJS LTS. For me, 11.7 Current was the issue. I combed the inter webs and discovered that Current doesn't get tested with NPM all the time, so in a way, Current is how that team tests NodeJS in the wild. Best of luck to anyone having this issue.



回答5:

i figured out that this could be due to various reasons, one could be node versions. but mostly and even in my case as @maury844 pointed out, it was due to ng serve running in another command prompt in parallel. deleting npm and npm-cache folders in appdata/roaming could also be related to this issue. try all these.