I’m trying to set up a new Angular project but running into issues with package installation. My environment details are:
- Node.js version: 8.9.2
- NPM version: 5.5.1
When I run the following command to install Angular CLI globally:
npm install -g @angular/cli
I get this error message:
npm ERR! Unexpected end of JSON input while parsing near '...nt-webpack-plugin":"0'
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Username\AppData\Roaming\npm-cache\_logs\2017-12-06T13_10_10_729Z-debug.log
This seems to be related to corrupted JSON data during the package download or parsing process. Has anyone encountered this type of installation error before? What steps can I take to resolve this issue and successfully install the Angular CLI?
This happens when npm can’t download or parse package metadata from the registry. I’ve hit this before - clearing the npm cache often isn’t enough. Delete your entire npm cache folder manually. On Windows, it’s at C:\Users\[Username]\AppData\Roaming\npm-cache. After deleting it, restart your command prompt as admin and try installing again. Still having issues? Update npm first with npm install -g npm@latest before installing Angular CLI. Newer versions handle network interruptions better.
Encountered this issue a while back on Windows, and it stemmed from a corrupted npm cache that disrupted the JSON parsing. I resolved it by executing npm cache clean --force and then reinstalling Angular CLI. If the problem persists, consider verifying your internet connection as interruptions can corrupt package metadata. Alternatively, switching to a different npm registry mirror might help if the default one is experiencing issues, which can happen during high traffic times.
had the same issue last month with angular. switch to yarn instead of npm - run yarn global add @angular/cli. way more reliable and doesnt get those weird json parsing errors. if you dont have yarn yet, just npm install -g yarn first then make the switch.