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 :)
@StephenFluin
A bit of comment-out-line-by-line debugging: The issue appears to be the
"root": "path-with-directory/slash"
if I remove the subdirectory, it works like a charm.
I'm also having the same issue for Clarity, which you can find our project at https://github.com/vmware/clarity/tree/website/latest. The angular-cli.json file is at https://github.com/vmware/clarity/blob/website/latest/.angular-cli.json.
➜ npm install @angular/cli@next
...
added 31 packages, removed 564 packages and updated 39 packages in 12.81s
➜ ng update @angular/cli --from=1 --migrate-only
The Angular CLI configuration format has been changed, and your existing configuration can
be updated automatically by running the following command:
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 838
I haven't been able to migrate even with the suggestion by @krotscheck.
@hansl I think we already fixed this one, can you check?
@krotscheck and @gnomeontherun can you try with @angular/[email protected]? Using your .angular-cli.json files and running ng update @angular/cli, I did not see the errors.
@filipesilva I have the same problem with @angular/[email protected] when upgrading from 1.7.4. My .angular-cli.json is
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "client"
},
"packageManager": "yarn",
"apps": [
{
"root": "src/browser",
"outDir": "../../Build/Client/ui",
"assets": [],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"tsconfig": "tsconfig.app.json",
"prefix": "app",
"styles": [
"styles/app.scss"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"lint": [
{
"project": "src/browser/tsconfig.app.json",
"exclude": "**/node_modules/**"
}
],
"defaults": {
"styleExt": "scss",
"class": {
"spec": false
},
"component": {
"spec": false
},
"directive": {
"spec": false
},
"guard": {
"spec": false
},
"module": {
"spec": false
},
"pipe": {
"spec": false
},
"service": {
"spec": false
}
}
}
The output
> 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 224
Versions
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 6.0.0-rc.7
Node: 10.0.0
OS: win32 x64
Angular: 6.0.0-rc.6
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.5.10
@angular-devkit/build-angular 0.5.10
@angular-devkit/build-optimizer 0.5.10
@angular-devkit/core 0.5.10
@angular-devkit/schematics 0.5.10
@angular/cli 6.0.0-rc.7
@ngtools/json-schema 1.1.0
@ngtools/webpack 6.0.0-rc.8
@schematics/angular 0.5.10
@schematics/update 0.5.10
rxjs 6.0.0
typescript 2.7.2
webpack 4.6.0
@filipesilva No luck from me, though likely for unrelated reasons. We just refactored into a yarn workspaces based monorepo, and attempting to migrate our project from within the child workspaces gave me this:
mkrotscheck-a02:ui-sdk mkrotscheck$ ng update @angular/cli --migrate-only --from=1
Could not find a package.json. Are you in a Node project?
I suspect that issue's reported elsewhere.
(Side note - yeah, I know ng now supports its own monorepo-style structure, and I'm trying to use it for a different project. In this one, unfortunately, we're shipping more-than-just angular packages, so I a more traditional monorepo is called for)
also getting this with rc.10:
$ ng update @angular/cli --migrate-only --from=1.7.4
Updating karma configuration
Updating configuration
Removing old config file (.angular-cli.json)
Writing config file (angular.json)
Invalid JSON character: "\"" at 10:22.
10:22 of the original file contains outDir, so I assume the numbers refer to the generated file.
I will not provide the entire .angular-cli.json file here as it is very large and contains multiple apps, but perhaps a --verbose mode would be helpful in order to debug these issues?
update: this is still an issue with 6.0 final
I can also confirm 6 final isn't working and get a very similar error
ng update @angular/cli --migrate-only --from=1.7.4
Updating karma configuration
Updating configuration
Removing old config file (.angular-cli.json)
Writing config file (angular.json)
Invalid JSON character: "\"" at 9:22.
I can confirm that the issue still exists in 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?
@hansl perhaps this should be reopened?
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.
For Invalid JSON character: "" at 0:0 please see the fix in #10715
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(),
...
This is a BOM bug that I've been following for a while. Dupe of #10644.
There is a similar bug (but much less fixable) for unicode characters in general, not sure how we're going to handle that one. For now, in most cases, PR angular/devkit#862 should fix this.
I fixed the issue by converting most .json files (tsconfig, etc.) to UTF8, without BOM.
All my files are UTF8 without BOM, but was still getting
Invalid JSON character: \ at 9:66.
{ "extends": "../tsconfig.json", "compilerOptions": { "outDir": "../out-tsc/spec", "module": "commonjs", "target": "es5", "baseUrl": "", "types": ["node", "jasmine"] }, "files": ["app-testbed.test.ts", "test.ts", "app-disco.test.ts" "shared/other/polyfills.ts" ,], "include": ["/*.spec.ts", "/*.d.ts"] }
I've commented out the ten or so lines in updateSpecTsConfig that appends the polyfills to the files and I'm rocking and rolling again.
@StrangeCargo74, the BOM only affects position 0,0 of the file. Your error is on line 9 at position 66 and you're missing a comma between "app-disco.test.ts" and "shared/other/polyfills.ts"