相关文章推荐
谦虚好学的钥匙  ·  Java 遍历JsonNode·  2 月前    · 
时尚的佛珠  ·  ILoggingEvent (The ...·  1 年前    · 
调皮的石榴  ·  Linux tar 命令 | 菜鸟教程·  3 年前    · 
爱喝酒的抽屉  ·  tsm configuration set ...·  3 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Error: "The operation was rejected by your operating system" when trying to create new angular project using windows powershell

Ask Question

I keep getting the same error message when trying to create a new angular project. I tried to create a new angular project using Windows Powershell with the following commands:

ng new hello-world

-> Would you like to add angular routing? - Yes

-> Stylesheet format? - CSS

I obtained the error message below. I already tried to reinstall angular cli and I'm running Powershell using Administrator.

Installed versions:

Angular CLI: 8.0.6

Node: 10.16.0

OS: win32 x64

Error message:

npm WARN tarball data for tslint@~5.15.0 (sha512-6bIEujKR21/3nyeoX2uBnE8s+tMXCQXhqMmaIPJpHmXJoBJPTLcI7/VHRtUwMhnLVdwLqqY3zmd8Dxqa5CVdJA==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for jasmine-spec-reporter@~4.2.1 (sha512-FZBoZu7VE5nR7Nilzy+Np8KuVIOxF4oXDPDknehCYBDE080EnlPu0afdZNmpGDBRCUBv3mj5qgqCRmk6W/K8vg==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for acorn@^6.0.5 (sha512-jPTiwtOxaHNaAPg/dmrJ/beuzLRnXtB0kQPQ8JpotKJgTB6rX6c8mlf315941pyjBSaPg8NHXS9fhP4u17DpGA==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for @angular/language-service@~8.0.3 (sha512-04XojOo9FJgEQE/rZafnaJQxPEU+//TSzTgpGoIVzCSMx+joCY/ZSSwJZPWxiHlOE57W/zX02ZY+TwcM81oTdw==) seems to be corrupted. Trying one more time.
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\konta\Desktop\Programming_files\Angular\hello-world\node_modules\.staging\@angular\platform-browser-447d0944\esm2015\animations\src\animation_builder.js'
npm ERR! path C:\Users\konta\Desktop\Programming_files\Angular\hello-world\node_modules\.staging\jasmine-spec-reporter-cbb15ffc\screenshot.gif
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall unlink
npm ERR! Error: EPERM: operation not permitted, unlink 'C:\Users\konta\Desktop\Programming_files\Angular\hello-world\node_modules\.staging\jasmine-spec-reporter-cbb15ffc\screenshot.gif'
npm ERR!  { [Error: EPERM: operation not permitted, unlink 'C:\Users\konta\Desktop\Programming_files\Angular\hello-world\node_modules\.staging\jasmine-spec-reporter-cbb15ffc\screenshot.gif']
npm ERR!   cause:
npm ERR!    { Error: EPERM: operation not permitted, unlink 'C:\Users\konta\Desktop\Programming_files\Angular\hello-world\node_modules\.staging\jasmine-spec-reporter-cbb15ffc\screenshot.gif'
npm ERR!      errno: -4048,
npm ERR!      code: 'EPERM',
npm ERR!      syscall: 'unlink',
npm ERR!      path:
npm ERR!       'C:\\Users\\konta\\Desktop\\Programming_files\\Angular\\hello-world\\node_modules\\.staging\\jasmine-spec-reporter-cbb15ffc\\screenshot.gif' },
npm ERR!   stack:
npm ERR!    'Error: EPERM: operation not permitted, unlink \'C:\\Users\\konta\\Desktop\\Programming_files\\Angular\\hello-world\\node_modules\\.staging\\jasmine-spec-reporter-cbb15ffc\\screenshot.gif\'',
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'unlink',
npm ERR!   path:
npm ERR!    'C:\\Users\\konta\\Desktop\\Programming_files\\Angular\\hello-world\\node_modules\\.staging\\jasmine-spec-reporter-cbb15ffc\\screenshot.gif',
npm ERR!   parent: 'hello-world' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm WARN tar EPERM: operation not permitted, lstat 'C:\Users\konta\Desktop\Programming_files\Angular\hello-world\node_modules\.staging\@angular\router-8388bfd5\esm2015\src\directives'
npm WARN tarball tarball data for typescript@3.4.4 (sha512-xt5RsIRCEaf6+j9AyOBgvVuAec0i92rgCaS3S+UVf5Z/vF2Hvtsw08wtUTJqp4djwznoAgjSxeCcU4r+CcDBJA==) seems to be corrupted. Trying one more time.
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\konta\AppData\Roaming\npm-cache\_logs\2019-07-01T01_21_13_653Z-debug.log
Package install failed, see above.
                This can happen with factory configuration in Windows 10 - I had the problem with Windows Defender - see also Qadir Hussain's answer.
– user1821237
                Jun 5, 2021 at 12:37

In windows10 I disabled the windows defender / windows security ==> realtime protection and try again npm install command and it worked

NOTE : Turn on the real time protection again after installation complete.

The issue with this is now you PC or laptop is not protected... There's an option in Windows Security that allows you to exclude files. – Edwin Pratt Jan 23, 2021 at 22:42 As an absolute newbie to Node, this is horrible. Why would a software as mature as nodejs would need to turn off the virus protection. This is wrong on many level. – Rajesh Swarnkar Feb 2, 2022 at 13:02 If you are running this command through a terminal in an IDE (eg: Webstorm etc.) you can run the IDE as administrator as well. Then the IDE terminals also get administrator privileges – Dilini Peiris Jul 1, 2022 at 6:18

I'd just like to add a small little answer based on Qadir Hussain's answer.

If you disable "Realtime Protection" in Windows Security, you're going to leave your laptop or PC vulnerable to any viruses that may infect it when "Realtime Protection" is off. This may seem a bit impossible if you're only installing an NPM package, but some apps may have a hidden background process waiting for "Realtime Protection" to be disabled, and when it is, it could inject a virus.

That been said, there's still an option.

  • First things first, open Windows Security by typing "Windows Security" in the Start Menu and tap "Open".
  • After that, go to "Virus & Threat Protection".
  • Next, scroll down until you find "Manage Settings" under "Virus & Threat Protection Settings".
  • Then, scroll down until you see "Exclusions". Under "Exclusions" there's a link that says "Add or remove exclusions".
  • Once that's done, tap the button that says "Add an exclusion". Then tap "Folder" on the drop-down menu.
  • Choose the node_modules directory that is giving issues.

  • Last but not least, Allow administrative permissions.

  • Finally, exit Windows Security.

    I wouldn't recommend excluding your entire Projects folder, as that will disable all scans for the directory.

    Small disclaimer here, I'm only making this answer as a means of helping others without disabling "Realtime Protection". While I'm not encouraging this, this might help fix a common problem.

    Have a good day. :)

    For me, there are several possibilities:

  • Intercepted by anti-virus software, resulting in inoperability.

  • It is locked by IDE, resulting in inoperable.

  • The task is locked by npm running, resulting in inoperable.

    For me the issue was with npm version I was using. I changed to a npm version which did not have the bug by using the below command:

    npm install --global npm@8.3.1
    

    I found this solution in a github issue:

    Link to github issue

    Hope it helps you like it did me!

    Cancelling the npm start process and closing the terminal window (I use Hyper Terminal) worked for me (using Win 10).

    I was then able to uninstall an npm package and install another.

    I had trouble installig npm packages for my React Native project and killing the npm start process worked for me. You have my thanks! – Delice Dec 24, 2020 at 14:45

    To me, using Windows 10 the only thing that solved this problem was: exclude the node_modules folder, open Visual Studio Code in Admin mode in the project folder, and execute the following command:

    npm install -g --unsafe-perm
    
  • make sure other processes does not occupying the folder/file
  • with me, it was not related to antivirus. it appears that a process occupied this folder. in my case a node process occupied my node_modules folder. i found it out by using process-explorer - i searched the path end found that a node process using this folder(even though I closed it! very common in windows), so i ended this process and then i did not got this error anymore.

    This happened when I tried installing a new npm dependency, jest, with:

    npm i --save-dev jest
    

    I got it working by simply rerunning the command.

  •