Skip to content

ng add @angular/pwa --project test-project failed to update package.json when application is under projects folder #12256

@playground

Description

@playground

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Command (mark with an x)

- [ ] new
- [ ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [x] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Versions

npm v6.4.0

Angular CLI: 6.2.1
Node: 9.4.0
OS: darwin x64
Angular: 6.1.7
... animations, common, compiler, compiler-cli, core, elements
... forms, http, language-service, platform-browser
... platform-browser-dynamic, router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.6.8
@angular-devkit/build-angular      0.6.8
@angular-devkit/build-ng-packagr   0.6.8
@angular-devkit/build-optimizer    0.6.8
@angular-devkit/core               0.6.8
@angular-devkit/schematics         0.8.1
@angular/cdk                       6.4.7
@angular/cli                       6.2.1
@angular/flex-layout               6.0.0-beta.17
@angular/material                  6.4.7
@angular/pwa                       0.8.1
@ngtools/json-schema               1.1.0
@ngtools/webpack                   6.0.8
@schematics/angular                0.8.1
@schematics/update                 0.8.1
ng-packagr                         3.0.0
rxjs                               6.3.2
typescript                         2.9.2
webpack                            4.8.3

MacOS High Sierra

Repro steps

ng add @angular/pwa --project test-project

The log given by the failure

npm ERR! file /my-project/package.json
npm ERR! code EJSONPARSE
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected token 
npm ERR! JSON.parse  in JSON at position 1205 while parsing '{
npm ERR! JSON.parse   "name": "my-project",
npm ERR! JSON.parse   "version": "0.0'
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.

Desired functionality

Should update package.json, but it's throwing the above errors when attempts to update package.json.
Looks like it's inserting "@angular/service-worker": "^6.1.7", in between the word "ro uter"

  "dependencies": {
    "@angular/animations": "^6.1.7",
    "@angular/cdk": "^6.4.7",
    "@angular/common": "^6.1.7",
    "@angular/compiler": "^6.1.7",
    "@angular/core": "^6.1.7",
    "@angular/elements": "^6.1.7",
    "@angular/flex-layout": "^6.0.0-beta.16",
    "@angular/forms": "^6.1.7",
    "@angular/http": "^6.1.7",
    "@angular/material": "^6.4.7",
    "@angular/platform-browser": "^6.1.7",
    "@angular/platform-browser-dynamic": "^6.1.7",
    "@angular/pwa": "^0.8.1",
    "@angular/ro
    "@angular/service-worker": "^6.1.7",uter": "^6.1.7",
    "@webcomponents/custom-elements": "^1.1.2",
    "cookies": "^0.7.1",
    "core-js": "^2.5.4",
    "crypto-js": "^3.1.9-1",
    "document-register-element": "1.8.1",
    "lodash-es": "^4.17.10",
    "material-design-icons": "^3.0.1",
    "ng-simple-slideshow": "^1.2.4",
    "ngx-cookie-service": "^1.0.10",
    "profanity-filter": "^0.2.1",
    "require": "^2.4.20",
    "rxjs": "^6.3.2",
    "rxjs-compat": "^6.2.0",
    "simplewebrtc": "^3.0.1",
    "webrtc-adapter": "^6.2.1",
    "zone.js": "^0.8.26"
  },

After running "ng add @angular/pwa --project test-project"

ng -v shows

Angular CLI: 6.2.1
Node: 9.4.0
OS: darwin x64
Angular: 
... 

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.8.1
@angular-devkit/core         0.8.1
@angular-devkit/schematics   <error>
@schematics/angular          <error>
@schematics/update           <error>
rxjs                         6.2.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions