-3

when i run "ng generate component " "unexpected token ] in json at position 800". When i type ng serve , the window is continuously running. any help please? PS E:\angulartutorial\my-first-app> ng generate component about Unexpected token ] in JSON at position 800 and when I run ng serve

  • 1
    We are always glad to help and support new coders but you need to help yourself first. :-) [After doing more research](https://meta.stackoverflow.com/q/261592/1011527) if you have a problem post what you've tried with a clear explanation of what isn't working and provide a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). Read [How to Ask](http://stackoverflow.com/help/how-to-ask) a good question. Be sure to [take the tour](http://stackoverflow.com/tour) and read [this](https://meta.stackoverflow.com/q/347937/1011527). – Dave Jun 07 '18 at 15:52
  • One of your .json files is probably missing a closing `]` bracket somewhere. Start by checking your `angular-cli.json`, `package.json`, etc... – Narm Jun 07 '18 at 15:54
  • To make it quick share your `angular.json` if you are using Angular V6 or `.angular-cli.json` if Angular <=V5 – Vikas Jun 07 '18 at 15:55
  • http://collabedit.com/eqcjp – Jayanth Kannan Jun 07 '18 at 20:07
  • i have added the code in collabedit link. i do not know how to share the code as a url.. that is why i have shared in collabedit.. – Jayanth Kannan Jun 07 '18 at 20:08
  • 2
    Possible duplicate of [ng generate component giving error "Unexpected token / in JSON at position 629"](https://stackoverflow.com/questions/50257785/ng-generate-component-giving-error-unexpected-token-in-json-at-position-629) – Vega Jan 21 '19 at 09:29

2 Answers2

3

Just to answer this for the benefit of searchers (and to confirm a statement in comments):

For me, the answer to this was an invalid character in angular.json (though someone else might find an issue in angular-cli.json or package.json, for me the culprit was angular.json).

Opening the file in Visual Studio Code helped identify the error (another editor thought it was valid).

In my case, the cause was that I had put a comment in the json.

E.g. In angular.json, this source provides the error:

"scripts": [
                /* boostrap.bundle includes popper.js */
                "node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"
            ]

ERROR: Unexpected token / in JSON at position 888

But remove the comment and it works e.g.

"scripts": [
                "node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"
            ]
JsAndDotNet
  • 16,260
  • 18
  • 100
  • 123
  • 1
    Just as an addition: The `angular.json` file will flag errors for things that might pass as valid JavaScript syntax. For me, I had the error `Unexpected token ] in JSON at position 986`, turns out it was because I had a `,` in between the last element of the array and the closing ] tag. So check for things like that too. – David Jul 22 '20 at 22:12
  • For me, it was the tsconfig file. – Wayne F. Kaskie Mar 24 '22 at 20:26
0

Make sure you are using correct schematicCollection in your angular.json

ie.

  "cli": {
    "packageManager": "npm",
    "schematicCollections": [
      "@angular/material"
    ]
  }

in my last incident, I was still using @nrwl/angular and this was the culprit for me. After changing to @angular/material it was resolved.