【问题标题】:Angular Cli Error: Unexpected token ] in JSON at position 1008Angular Cli 错误:位置 1008 的 JSON 中的意外标记]
【发布时间】:2018-07-03 20:02:48
【问题描述】:

我在生成组件和服务时遇到问题。 我在位置 1008 处的 JSON 中收到错误“Unexpected token ]” 我唯一有那么长的文件是 package-lock.json 但即使在我使用 rm package-lock.json 之后,我仍然收到相同的错误消息(尽管我没有该文件)。 我以前可以在 cli 上添加组件,但我不知道发生了什么变化,现在我不能。 我将最近更改的文件和 json 文件放在这里:

angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "LG-Academy": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "lg",
      "schematics": {
        "@schematics/angular:component": {
          "styleext": "sass"
        }
      },
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/LG-Academy",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.sass",
              "node_modules/bootstrap/dist/css/bootstrap.min.css",
              "node_modules/font-awesome/scss/font-awesome.scss",
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.min.js",
              "node_modules/popper.js/dist/umd/popper.min.js",
              "node_modules/bootstrap/dist/js/bootstrap.min.js"
            ]
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "LG-Academy:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "LG-Academy:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "LG-Academy:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "styles": [
              "src/styles.sass"
            ],
            "scripts": [],
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },
    "LG-Academy-e2e": {
      "root": "e2e/",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "LG-Academy:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "LG-Academy:serve:production"
            }
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "LG-Academy"
}

package.json

{
  "name": "lg-academy",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.0.3",
    "@angular/common": "^6.0.3",
    "@angular/compiler": "^6.0.3",
    "@angular/core": "^6.0.3",
    "@angular/forms": "^6.0.3",
    "@angular/http": "^6.0.3",
    "@angular/platform-browser": "^6.0.3",
    "@angular/platform-browser-dynamic": "^6.0.3",
    "@angular/router": "^6.0.3",
    "@fortawesome/fontawesome-free": "^5.1.0",
    "angular-font-awesome": "^3.1.2",
    "bootstrap": "^4.1.1",
    "core-js": "^2.5.4",
    "font-awesome": "^4.7.0",
    "jquery": "^3.3.1",
    "popper.js": "^1.14.3",
    "rxjs": "^6.0.0",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular/compiler-cli": "^6.0.3",
    "@angular-devkit/build-angular": "~0.6.8",
    "typescript": "~2.7.2",
    "@angular/cli": "~6.0.8",
    "@angular/language-service": "^6.0.3",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1"
  }
}

./courses/course.service

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

import { Observable, throwError } from 'rxjs';
import { map, tap, catchError } from 'rxjs/operators';

import { ICourse } from './course';

@Injectable()
export class CourseService{
  private courseUrl = 'http://localhost:300/courses.json';

  constructor(private http: HttpClient) {}
}

/.courses/course-list/course-list.component

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';

import { ICourse } from '../course';
import { CourseService } from '../course';

@Component({
  selector: 'lg-course-list',
  templateUrl: './course-list.component.html',
  styleUrls: ['./course-list.component.sass']
})

export class CourseListComponent implements OnInit {
  pageTitle = "LabGuru Academy";

  constructor() { }

  ngOnInit() { }

}

/.courses/course.ts

export interface ICourse {
  course_id: number;
  title: string;
  autor: string;
}

【问题讨论】:

    标签: angular angular-cli angular-cli-v6


    【解决方案1】:

    删除行中的 tariling 逗号: "node_modules/font-awesome/scss/font-awesome.scss",

    【讨论】:

    • 天哪,我没注意到!我觉得自己很愚蠢哈哈非常感谢你!
    • 并非总是如此,但当错误提示“意外令牌”时,这是因为存在格式错误的 json 对象。在您的情况下是一个相当大的对象,因此要调试您可以使用像 jsonformatter.curiousconcept.com 这样的 json 验证器
    猜你喜欢
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 2019-05-15
    • 1970-01-01
    • 2017-10-21
    • 1970-01-01
    • 2018-08-08
    • 2018-10-11
    相关资源
    最近更新 更多