I’m trying to set up a new Angular 5 development environment and running into a frustrating issue. My system is running Node.js version 8.9.2 and npm version 5.5.1.
When I try to execute the following command:
npm install -g @angular/cli
I keep getting 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\Aashitec\AppData\Roaming\npm-cache\_logs\2017-12-06T13_10_10_729Z-debug.log
This seems to be related to corrupted package metadata or incomplete JSON files in the npm registry. Has anyone encountered this specific parsing error before? What would be the best way to resolve this installation problem and get Angular CLI working properly?
yeah, ran into this too! updating npm helped me a lot: npm install -g npm@latest makes sure u got the latest stuff. sometimes the old versions just cant handle the newer package.json data. good luck!
Had this exact error when setting up multiple Angular projects last year. The truncated JSON happens when npm downloads get cut off mid-stream. What worked for me: switch to a different network first, then clear everything out. Delete node_modules if it exists, run npm cache verify to check for corruption, and install with npm install -g @angular/cli --no-cache. Sometimes npm servers have temporary issues serving complete package data. If you’re still stuck, try yarn instead of npm for the global install - it handles network interruptions better. The Angular CLI works fine either way.
The issue you’re experiencing typically arises from a corrupted npm cache. I’ve encountered similar problems previously while working with Angular and older npm setups. It often results from incomplete downloads or network interruptions. Start by executing npm cache clean --force. If that doesn’t work, you may need to manually clear the contents of C:\Users\Aashitec\AppData\Roaming\npm-cache. After doing that, restart your command prompt as an administrator and attempt the installation again. Additionally, running the command with --verbose can provide more insight into where the failure is occurring. In some cases, changing the registry to npm config set registry https://registry.npmjs.org/ can also resolve issues stemming from registry corruption.
This error drove me crazy for weeks during a migration. It happens when npm’s package-lock.json or registry data gets corrupted during download. I tried all the usual cache fixes - nothing worked. What finally solved it was switching npm registries temporarily. Check your current registry with npm config get registry, then switch with npm config set registry https://registry.yarnpkg.com/. Install Angular CLI, then switch back. The alternative registry usually has cleaner metadata. Pro tip: use npm install -g @angular/cli@latest instead of letting npm pick the version - it bypasses corrupted version references in the registry index.