angular-cli: Upgrading to angular 6 fails during angular-cli migration with unexpected token.

Versions

6.0.0-rc.5

Repro steps

ng update @angular/cli --migrate-only --from=1

using the following .angular-cli.json file.

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "ui-sdk"
  },
  "packageManager": "yarn",
  "apps": [
    {
      "name": "lib",
      "root": "src/lib",
      "outDir": "lib",
      "assets": [],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "sym",
      "styles": [],
      "scripts": [
        "../../node_modules/@webcomponents/custom-elements/custom-elements.min.js"
      ],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    },
    {
      "name": "demo",
      "root": "src/demo",
      "outDir": "demo",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "test": "test.ts",
      "polyfills": "polyfills.ts",
      "tsconfig": "tsconfig.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "sym",
      "styles": [
        "vendor.scss",
        "styles.scss"
      ],
      "scripts": [
        "../../node_modules/@webcomponents/custom-elements/custom-elements.min.js",
        "../../vendor/vts.js"
      ],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts",
        "e2e": "environments/environment.e2e.ts",
        "upgrade": "environments/environment.upgrade.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "src/lib/tsconfig.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "src/lib/tsconfig.spec.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "src/demo/tsconfig.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "src/demo/tsconfig.spec.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "src/testing/tsconfig.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "src/cli/tsconfig.json",
      "exclude": "**/node_modules/**"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "css"
  }
}

Observed behavior

mkrotscheck-a02:sdk mkrotscheck$ ng update @angular/cli --migrate-only --from=1
            Updating karma configuration
            Updating configuration
            Removing old config file (.angular-cli.json)
            Writing config file (angular.json)
Unexpected token / in JSON at position 240

Desired behavior

Successful app migration, or helpful error 😃

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 35 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Hey, After alot of research, I have come up with following solution and got success in updating my local project to Angular 6.0.1:

  1. npm install @angular/{animations,common,compiler,compiler-cli,core,forms,http,platform-browser,platform-browser-dynamic,platform-server,router}@‘6.0.1’
  2. ng update rxjs
  3. npm install rxjs@6 rxjs-compat@6 --save
  4. ng update @angular/core
  5. ng update @angular/material
  6. npm install typescript@‘>=2.7.0 <2.8.0’

Please respond and share! Thanks

update: this is still an issue with 6.0 final

I am getting a slightly different error (6.0 final)

ng update @angular/cli
            Updating karma configuration
            Updating configuration
            Removing old config file (.angular-cli.json)
            Writing config file (angular.json)
Invalid JSON character: "" at 0:0.

I can’t see how there is a problem at 0:0. The first character in .angular-cli.json is an open bracket {. Is there an encoding issue or something?

I can confirm that the issue still exists in 6.0 final

Right, so I’ve done some digging around and found that it’s not actually the writing of the angular.json file that fails. The error comes from the following step in updateSpecTsConfig(config):

const tsCfgAst = core_1.parseJsonAst(
        buffer.toString(),
        core_1.JsonParseMode.Loose
      );

Writing the buffer to console reveals the following string:

{
  "extends": "../../../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/spec",
    "baseUrl": "../../../",
    "module": "commonjs",
    "target": "es5",
    "types": ["jasmine", "node"],
    "strict": false
  },
  "files": ["test.ts"  "polyfills.ts"
  ,],
  "include": ["./**/*.spec.ts", "**/*.d.ts", "**/*.ts", "../../../conf/**/*.ts"]
}

Which fails on the line "files": ["test.ts" "polyfills.ts"

However, when inspecting the actual file, it only has "files": ["test.ts"] None of the tsconfig.spec.json files have any reference to polyfills.ts, so it’s still a mystery how or why this suddenly shows up.

Commenting out that part from the chain, and the rest of the processes run by smoothly: node_modules/@schematics/angular/migrations/update-6/index.js

...
return schematics_1.chain([
      migrateKarmaConfiguration(config),
      migrateConfiguration(config),
      // updateSpecTsConfig(config),
      updatePackageJson(config),
      updateTsLintConfig(),
      ...

For Invalid JSON character: "" at 0:0 please see the fix in #10715

I had similar problem, updating Node from v6.10.2 to v10.1.0 did the trick.

I’m getting the same as Swellenator in 6.0 final. My “root” = “src”

Note: I had to delete a private npm package reference in order to get past a “not found” error but then I got this error. Probably unrelated but wanted to mention it in case.

@krotscheck and @gnomeontherun can you try with @angular/cli@6.0.0-rc.7? Using your .angular-cli.json files and running ng update @angular/cli, I did not see the errors.