Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Error: Unexpected end of JSON input" when trying to update Angular from 5.2 to 6.0

I am attempting to update an old Angular project that has not been updated for a long time from Angular 5.2 to 13.0. I am following the Angular guide (https://update.angular.io/?l=2&v=5.0-13.0) but am getting a Unexpected end of JSON input error when I try follow the recommended command to upgrade from 5.2 to 6.0:

Command:cmd /C "set "NG_DISABLE_VERSION_CHECK=1" && npx @angular/cli@6 update @angular/cli@6 @angular/core@6"

Error message:

Error: Unexpected end of JSON input
Unexpected end of JSON input

I get the same error as above when I do ng update as well, with no indication of which file is causing this error.

The full error message and command I use can be seen here (note there is also a global vs local version warning, but I can't seem to find where the newer global version is even located or if that is related to this error: Picture of error message

The application runs fine, so I am not sure where there could be a corrupt JSON file, and the error gives no indication of what JSON it is struggling to interpret, any help would be much appreciated.

Versions:

Output of ng --version is:

Angular CLI: 1.7.4
Node: 8.9.0
OS: win32 x64
Angular: 5.2.9
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.7.4
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/core: 0.3.2
@angular-devkit/schematics: 0.3.2
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.2
@schematics/angular: 0.3.2
@schematics/package-update: 0.3.2
typescript: 2.5.3
webpack: 3.11.0
like image 428
Ben Avatar asked Nov 01 '25 13:11

Ben


2 Answers

I also had the same issue while upgrading from angular 5.2 to 6. This is probably due to your node global version. Mine was node 18.10.0, I completely uninstalled node and installed the lower version 14.17.6 and the upgrade was successful!.

like image 94
Jayakrishnan M.S. Avatar answered Nov 04 '25 03:11

Jayakrishnan M.S.


First, I manually deleted the package-lock.json file. Then:

  • npm cache clean --force
  • npm install
  • cmd /C "set "NG_DISABLE_VERSION_CHECK=1" && npx @angular/cli@6 update @angular/cli@6 @angular/core@6"

Another option is to change the node version to a version lower than 14.20.1. I switched to 14.15.4 using:

  • nvm use 14.15.4 (nvm and the desired node version must be installed beforehand)

Another option is to check that the dependencies are correctly specified in the package.json file.

If nothing works, manually change the dependencies in the package.json file, delete the node_modules folder, and run:

  • npm install.
like image 36
Carlota Juncosa Avatar answered Nov 04 '25 03:11

Carlota Juncosa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!