Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error showed up while run the command ng generate module about #10880

Closed
leoliuasia opened this issue May 16, 2018 · 15 comments
Closed

Error showed up while run the command ng generate module about #10880

leoliuasia opened this issue May 16, 2018 · 15 comments

Comments

@leoliuasia
Copy link

Versions

λ ng --version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 6.0.1
Node: 9.8.0
OS: win32 x64
Angular: 6.0.2
... animations, 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
@angular/cli                      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 new nebular-demo
  • cd nebular-demo
  • ng serve
  • ng generate module about

Observed behavior

λ ng generate module about
Unexpected token ] in JSON at position 720

Same error when run command ng generate component about

What is happening?

@phl3x0r
Copy link

phl3x0r commented May 16, 2018

Perhaps an issue with the encoding of angular.json, it's just a guess based on other related issues.
Try converting your angular.json file to utf-8 without BOM and see if that helps.
And of course verify that angular.json contains only valid json :-)

@leoliuasia
Copy link
Author

Thanks for the reply! The encoding of angular.json is the utf-8 without BOM. And It is a valid json file. Actually I haven't done anything with the angular.json. It is just a new project generated using angular-cli.

@hitokiri
Copy link

I same problem

Angular CLI: 6.0.2
Node: 8.11.2
OS: linux x64
Angular: 6.0.2
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, http, language-service, material, 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.2
@ngtools/webpack                  6.0.1
@schematics/angular               0.6.2
@schematics/update                0.6.2
rxjs                              6.1.0
typescript                        2.7.2
webpack                           4.6.0

display error
Unexpected token ] in JSON at position 1337

@xlxAciDxlx
Copy link

xlxAciDxlx commented May 20, 2018

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


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

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.3
@angular-devkit/build-angular     0.6.3
@angular-devkit/build-optimizer   0.6.3
@angular-devkit/core              0.6.3
@angular-devkit/schematics        0.6.3
@angular/cli                      6.0.3
@ngtools/webpack                  6.0.3
@schematics/angular               0.6.3
@schematics/update                0.6.3
rxjs                              6.1.0
typescript                        2.7.2
webpack                           4.8.3

Same thing here. I'd be able to fix it myself if it at least said what file the error was found in.. I've checked every JSON file I can find (including angular.json), and all of them are valid.

Calling: ng g c components/index
Error: Unexpected token } in JSON at position 1333

@leoliuasia
Copy link
Author

It looks like not just me had the problem, I think it may be an encoding problem, but not sure where it is.

@xlxAciDxlx
Copy link

It looks like not just me had the problem

When I searched for the issue (to see if it already existed), yours was the first of many that had come up.

but not sure where it is

Yeah, same issue here. Running a linter and tsc all work fine, it just seems to be generating things that's broken for me.

@xlxAciDxlx
Copy link

Alright, my issue's fixed. It appears the error's caused by something being wrong in angular.json - I must've missed it when manually looking through my files. I threw it in JSONLint and it immediately threw an error. You can obviously do this for other files, but I'm going to assume this error is mainly caused by angular.json.

@leoliuasia
Copy link
Author

I’ll try it to see if it works for me.

@leoliuasia
Copy link
Author

leoliuasia commented May 22, 2018

I have found the problem. check the angular.json file.

"assets": [
              "src/favicon.ico",
              "src/assets",
            ],
            "styles": [
              "src/styles.css",
              "./node_modules/bootstrap/dist/css/bootstrap.css",
              "./node_modules/@nebular/theme/styles/prebuilt/default.css",
            ],

just remove the comma after "src/assets" and "...default.css"
like below:

"assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css",
              "./node_modules/bootstrap/dist/css/bootstrap.css",
              "./node_modules/@nebular/theme/styles/prebuilt/default.css"
            ],

then will fix the problem.
Somehow if the comma is in js code it will work. But not here.

Thanks to @xlxAciDxlx !

@hitokiri
Copy link

I do not have the commas, which you mention and I keep giving the error.

@xlxAciDxlx
Copy link

@leoliuasia Glad you were able to get it fixed :D

@hitokiri Did you try running your angular.json through JSONLint? Even if you don't have the commas, could be some other minor error messing it up.

@leoliuasia
Copy link
Author

@hitokiri May be you need to check the other positons that not same as my. Or just use the JSONLint tool mentioned by @xlxAciDxlx

Brocco added a commit to Brocco/angular-cli that referenced this issue Jun 6, 2018
Brocco added a commit to Brocco/angular-cli that referenced this issue Jun 7, 2018
Brocco added a commit to Brocco/angular-cli that referenced this issue Jun 8, 2018
Brocco added a commit to Brocco/angular-cli that referenced this issue Jun 8, 2018
Brocco added a commit to Brocco/angular-cli that referenced this issue Jun 8, 2018
filipesilva pushed a commit to filipesilva/angular-cli that referenced this issue Jun 11, 2018
filipesilva pushed a commit to filipesilva/angular-cli that referenced this issue Jun 13, 2018
@shinks21
Copy link

@leoliuasia thank you! I had the same error and running my angular.json through json found the issue. There was a comment in the file that I had to remove. ng generate component works now.

@kaziupir
Copy link

I had comma in tsconfig.json, so try to check all json files in json lint.

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants