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 :)
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); // } // }
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:
- npm install @angular/{animations,common,compiler,compiler-cli,core,forms,http,platform-browser,platform-browser-dynamic,platform-server,router}@'6.0.1'
- ng update rxjs
- npm install rxjs@6 rxjs-compat@6 --save
- ng update @angular/core
- ng update @angular/material
- npm install typescript@'>=2.7.0 <2.8.0'
Please respond and share! Thanks
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
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.
I had similar problem, updating Node from v6.10.2 to v10.1.0 did the trick.
I fixed the issue by converting the following .json files (tsconfig, angular-cli.json, tslint) to UTF8, without BOM.
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?
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.
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 .
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 !!
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
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
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
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)
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.