简体   繁体   中英

How to fix JSON error while building the project with Angular

I have an error during build process with Angular when I append --prod attribute to this command:

$ ng build --prod

Date: 2018-10-02T12:56:57.694Z
Hash: beece2bded30e9ac9066
Time: 26183ms
chunk {0} runtime.ec2944dd8b20ec099bf3.js (runtime) 1.44 kB [entry] [rendered]
chunk {1} main.3ffdf05fa00462e0d2af.js (main) 285 kB [initial] [rendered]
chunk {2} polyfills.7f205259d3713dc1e37e.js (polyfills) 38.4 kB [initial] [rendered]
chunk {3} styles.e206debd23d3c81eccf6.css (styles) 166 bytes [initial] [rendered]
Unexpected token : in JSON at position 541
SyntaxError: Unexpected token : in JSON at position 541
    at JSON.parse (<anonymous>)
    at MapSubscriber.host.exists.pipe.operators_1.map.content [as project] (/home/ubuntu/workspace/test/todo-app/node_modules/@angular-devkit/build-angular/src/angular-cli-files/utilities/service-worker/index.js:96:41)
    at MapSubscriber._next (/home/ubuntu/workspace/test/todo-app/node_modules/rxjs/internal/operators/map.js:49:35)
    at MapSubscriber.Subscriber.next (/home/ubuntu/workspace/test/todo-app/node_modules/rxjs/internal/Subscriber.js:67:18)
    at SwitchMapSubscriber.notifyNext (/home/ubuntu/workspace/test/todo-app/node_modules/rxjs/internal/operators/switchMap.js:86:26)
    at InnerSubscriber._next (/home/ubuntu/workspace/test/todo-app/node_modules/rxjs/internal/InnerSubscriber.js:28:21)
    at InnerSubscriber.Subscriber.next (/home/ubuntu/workspace/test/todo-app/node_modules/rxjs/internal/Subscriber.js:67:18)
    at Observable.rxjs_1.Observable.obs [as _subscribe] (/home/ubuntu/workspace/test/todo-app/node_modules/@angular-devkit/core/node/host.js:172:21)
    at Observable._trySubscribe (/home/ubuntu/workspace/test/todo-app/node_modules/rxjs/internal/Observable.js:44:25)
    at Observable.subscribe (/home/ubuntu/workspace/test/todo-app/node_modules/rxjs/internal/Observable.js:30:22)
    at /home/ubuntu/workspace/test/todo-app/node_modules/rxjs/internal/util/subscribeTo.js:22:31
    at Object.subscribeToResult (/home/ubuntu/workspace/test/todo-app/node_modules/rxjs/internal/util/subscribeToResult.js:10:45)
    at SwitchMapSubscriber._innerSub (/home/ubuntu/workspace/test/todo-app/node_modules/rxjs/internal/operators/switchMap.js:65:54)
    at SwitchMapSubscriber._next (/home/ubuntu/workspace/test/todo-app/node_modules/rxjs/internal/operators/switchMap.js:55:14)
    at SwitchMapSubscriber.Subscriber.next (/home/ubuntu/workspace/test/todo-app/node_modules/rxjs/internal/Subscriber.js:67:18)
    at Observable.rxjs_1.Observable.obs [as _subscribe] (/home/ubuntu/workspace/test/todo-app/node_modules/@angular-devkit/core/node/host.js:241:21)

I have no clue what's going wrong and how to fix this error.

Also there is no issue just for ng build command without --prod attribute in my case now.

Furthermore I've added PWA stuff to my app by this command add @angular/pwa as shown in this tutorial .

How to fix this error? Any advice will be appreciated.

I struggled for an hour on this error today.

My issue was in ngsw-config.json . My file was not valid json.

The error stacktrace does not point clearly to the file.
Make sure this file is valid with jsonlint.com as pointed by tenor528.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM