14

I just cloned an angular 6 project from bitbucket, did npm install and all the related tasks, it seems to be working well, but when I try to generate a new component using the angular-cli tool "ng generate component", I get the error

"Unexpected token / in JSON at position 629"

How can I fix this?

n4m31ess_c0d3r
  • 3,028
  • 5
  • 26
  • 35
Larry
  • 151
  • 2
  • 6
  • You should the full error logs – n4m31ess_c0d3r May 09 '18 at 19:09
  • Angulare CLI is a bit all over the place since the recent version 6. You can report this on their github, https://github.com/angular/angular-cli – IrishDubGuy May 22 '18 at 10:20
  • I had the same issue in Angular 6. $ ng generate component Dashboard Unexpected token / in JSON at position 1874 and I came here because I have no idea which Json file it is referring to. I looked through every single one outside the node folder and none of them are that long. – Dave Shinkle Jun 16 '18 at 21:29
  • @IrishDubGuy's suggestion below fixed this issue for me, which was reading that angular-cli issues page. Running my angular.json file through jslint (online) exposed an error in it. Not on the line they suggest through. – Dave Shinkle Jun 16 '18 at 21:38
  • Try validating you json file here: https://jsonformatter.curiousconcept.com/ If you have a problem with this fix it and try again. – Oscar Alexis Rivera Cabezas May 22 '19 at 15:50

4 Answers4

33

Check if you accidentally made a comment. Open up angular.json and look for '/' on the line or 'position' specified. JSON does not support comments.

Pang
  • 9,564
  • 146
  • 81
  • 122
Chloe Corrigan
  • 361
  • 2
  • 4
  • 2
    Thanks, man you are just life savior... I found I delete some lines which left over commas in json..and led to this error... – AlokeT Jul 27 '18 at 17:50
  • 1
    There are variations of this error with different positions numbers, it will be helpful to view the angular.json file in an editor with syntax highlighting to fix this error. – draysams Dec 17 '18 at 23:01
7

I also had same problem, when I trying to create component and after googling, I found https://jsonlint.com/ and which validate your JSON files and it points to the exact line and error.

For more information, please refer to following thread: https://github.com/angular/angular-cli/issues/10880

Cheers!

Sudhir
  • 126
  • 4
  • 11
4

Probably a problem in your angular.json somewhere, or maybe an encoding issue with the file or else a bug in Angular CLI. This is a reasonable place to start to investigate (one of the many Angular CLI github issues related to unexpected token errors)...https://github.com/angular/angular-cli/issues/10880

IrishDubGuy
  • 1,053
  • 2
  • 9
  • 18
  • 1
    This suggestion led to the fix for me. Running my angular.json through jslint exposed a problem with it (a comment inside it). Removing that fixed the issue and I could then run ng generate component. – Dave Shinkle Jun 16 '18 at 21:36
0

I Just changed the encoding to UTF-8 of Angular-CLI.JSON using notepad++ and issue resolved.

UTF-8

Zeeshanef
  • 639
  • 3
  • 14
  • 23