angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

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

Open krotscheck opened this issue 8 years ago • 35 comments

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 :)

krotscheck avatar Apr 19 '18 20:04 krotscheck

Indeed cado1982. There are two problems here, one is with the BOM (error at line 0), and another (i think) is the polyfills setting being incorrectly copied across during the update (error at line 9ish)

Just to be clear, my snippet is the console log of the buffer created in the updateSpecTsConfig function showing where the internal buffer was incorrect. I fixed it by commenting out the following lines in that function and copying the settings across manually.

// const polyfills = app.polyfills || defaults.polyfills; // if (!filesAstNode) { // // Do nothing if the files array does not exist. This means exclude or include are // // set and we shouldn't mess with that. // } else { // if (filesAstNode.value.indexOf(polyfills) == -1) { // json_utils_1.appendValueInAstArray(recorder, filesAstNode, polyfills); // } // }

StrangeCargo74 avatar May 09 '18 16:05 StrangeCargo74

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

Rumsha001 avatar May 15 '18 12:05 Rumsha001

I confirm the solution of @phl3x0r. It's crazy, I know, but removing all lines in tsconfig files with test.ts and so on, I fixed this error.

PS: I'm using angular-cli 6.0.1

Ks89 avatar May 15 '18 19:05 Ks89

In my case, I had commented a script array entry with /*..*/ in angular.json. Removing this resolved the error. I believe it happened because JSON doesn't support any comments as per specification.

andynrkri avatar May 16 '18 03:05 andynrkri

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

affilnost avatar May 16 '18 08:05 affilnost

I fixed the issue by converting the following .json files (tsconfig, angular-cli.json, tslint) to UTF8, without BOM.

bandersen22000 avatar May 28 '18 12:05 bandersen22000

I have followed https://update.angular.io/ and When I run 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.

Anyone know?

JigneshPatel04 avatar May 29 '18 12:05 JigneshPatel04

I was using visual studio code, i noticed the file encoding for angular-cli.json and package.json is UTF-8 and BOM, press on the label in the bottom then save with encoding and choose UTF-8. That's worked for me.

Al-Sharif avatar Jun 04 '18 06:06 Al-Sharif

My project tsconfig.json and tslint.json with UTF-8 and BOM so I choose UTF-8 and resolve it ago. but thanks to reply .

JigneshPatel04 avatar Jun 04 '18 10:06 JigneshPatel04

Guys, I was having the same problem and managed to fix just leaving the tslint.json file as it was by default.

To avoid tslint "errors" I had commented on some of the lines that he understands as error, but that are not ... (whitespace true - for example)

Just correcting this, he did the update normally!

Hope this helps someone else.

Good luck !!

dmsysop avatar Jun 13 '18 11:06 dmsysop

You not only have to change tslint.json, you have to change also in folder "src" the tsconfigs , test.ts, . Any that is affected on this update

neridonk avatar Jun 21 '18 08:06 neridonk

I am also facing a similar issue. I've detailed it here, if someone can have a look please. https://github.com/angular/angular-cli/issues/11825

bhaidar avatar Aug 10 '18 14:08 bhaidar

I my case I was getting the following error:

Unexpected token T in JSON at position 0 TF400813: Resource not available for anonymous access. Client authentication required.

The solution in my case could be found on this stackoverflow post

RicardoGomesRocha avatar Sep 25 '18 10:09 RicardoGomesRocha

trying create a jhipster project with angular 6 .when i run "ng serve" command ,i took error in below. please help me Could not determine a single project for the 'serve' target. Error: Could not determine a single project for the 'serve' target. at ServeCommand.getProjectNamesByTarget (C:\Users\pc\complexdemo\node_modules@angular\cli\models\architect-command.js:184:19) at MergeMapSubscriber._loadWorkspaceAndArchitect.pipe.operators_1.concatMap [as project] (C:\Users\pc\complexdemo\node_modules@angular\cli\models\architect-command.js:58:43) at MergeMapSubscriber._tryNext (C:\Users\pc\complexdemo\node_modules\rxjs\internal\operators\mergeMap.js:122:27) at MergeMapSubscriber._next (C:\Users\pc\complexdemo\node_modules\rxjs\internal\operators\mergeMap.js:112:18) at MergeMapSubscriber.Subscriber.next (C:\Users\pc\complexdemo\node_modules\rxjs\internal\Subscriber.js:103:18) at TapSubscriber._next (C:\Users\pc\complexdemo\node_modules\rxjs\internal\operators\tap.js:109:26) at TapSubscriber.Subscriber.next (C:\Users\pc\complexdemo\node_modules\rxjs\internal\Subscriber.js:103:18) at MergeMapSubscriber.notifyNext (C:\Users\pc\complexdemo\node_modules\rxjs\internal\operators\mergeMap.js:141:26) at InnerSubscriber._next (C:\Users\pc\complexdemo\node_modules\rxjs\internal\InnerSubscriber.js:30:21) at InnerSubscriber.Subscriber.next (C:\Users\pc\complexdemo\node_modules\rxjs\internal\Subscriber.js:103:18)

xtrrdnryprgrmmr avatar Oct 15 '18 14:10 xtrrdnryprgrmmr

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.