Angular-cli: Angular CLI: 6.0.1 - Unexpected token } in JSON at position 2686

Created on 14 May 2018  路  14Comments  路  Source: angular/angular-cli

Hi, when I try to create a component, I have this error :
Unexpected token } in JSON at position 2686

Versions

Angular CLI: 6.0.1
Node: 10.0.0
OS: darwin x64
Angular: 6.0.0
... animations, common, compiler-cli, core, forms, http
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.1
@angular-devkit/build-angular     0.6.1
@angular-devkit/build-optimizer   0.6.1
@angular-devkit/core              0.6.1
@angular-devkit/schematics        0.6.1
@angular/cdk                      6.0.1
@angular/cli                      6.0.1
@angular/compiler                 6.0.1
@angular/flex-layout              6.0.0-beta.15
@angular/material                 6.0.1
@ngtools/webpack                  6.0.1
@schematics/angular               0.6.1
@schematics/update                0.6.1
rxjs                              6.1.0
typescript                        2.7.2
webpack                           4.6.0

Repro steps

ng g c listsample
Unexpected token } in JSON at position 2686

Most helpful comment

When you call ng generate, it reads the angular.json file in your project. I had a similar issue, except mine was "Unexpected token /". I had commented out portions of the json file. The CLI did not like the my use of "//", so I had to remove the commented out sections, and it started working fine after that. So comb through your angular.json file, you probably have some malformed code in it.

All 14 comments

Same error here but in another line:

Unexpected token } in JSON at position 1075

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

Package                           Version
@angular-devkit/architect         0.6.1
@angular-devkit/build-angular     0.6.1
@angular-devkit/build-optimizer   0.6.1
@angular-devkit/core              0.6.1
@angular-devkit/schematics        0.6.1
@ngtools/webpack                  6.0.1
@schematics/angular               0.6.1
@schematics/update                0.6.1
rxjs                              6.1.0
typescript                        2.7.2
webpack                           4.6.0

I've updated Node to 10.1 and it's working...

Angular CLI: 6.0.1
Node: 10.1.0
OS: win32 x64
Angular:
...

Package                      Versio
-----------------------------------
@angular-devkit/architect    0.6.1
@angular-devkit/core         0.6.1
@angular-devkit/schematics   0.6.1
@schematics/angular          0.6.1
@schematics/update           0.6.1
rxjs                         6.1.0
typescript                   2.7.2

Updated as well to Node 10.1.0 as suggested by @ToniJM
Same problem on my side ;(
Unexpected token } in JSON at position 2686

Angular CLI: 6.0.1
Node: 10.1.0

When you call ng generate, it reads the angular.json file in your project. I had a similar issue, except mine was "Unexpected token /". I had commented out portions of the json file. The CLI did not like the my use of "//", so I had to remove the commented out sections, and it started working fine after that. So comb through your angular.json file, you probably have some malformed code in it.

@briangullo you're right. Thanks!
My JSON had this issue (the comma after "error", last line...).

   "en": {
          "aot": true,
          "outputPath": "dist/myapp-en/",
          "i18nFile": "src/locale/messages.en.xlf",
          "i18nFormat": "xlf",
          "i18nLocale": "en",
          "i18nMissingTranslation": "error", // REMOVE COMMA HERE
        }

@briangullo same problem here, thanks.

Unexpected token ] in JSON at position 434

I pasted my angular.json file into a json validator and it clean. not sure where to look now.

Use
These Command

  1. ng update
  2. ng update@ angular/cli

I received this error as well. "Unexpected token }" or "]" probably means you put a comma after the last element. The error message doesnt provide the file name or line number but I'm guessing position is characters from start of file. I just opened angular.json in vim and the culprit was highlighted.

Also, come on JSON specification, is that comma hurting anyone? ;)

delete package-lock.json

JSON is malformed, you can easily spot the error at https://jsonlint.com/

In my case I had a trailing ',' after one of my style imports in angular.json

i used this command it resolved my issue
ng update@ angular/cli

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings