如何在使用Angular构建项目时修复JSON错误

时间:2018-10-02 13:32:23

标签: javascript angular build frontend

当我将mnv clean test 属性附加到此命令时,在使用Angular的构建过程中出现错误:

$ ng build --prod

--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) 属性的ng build命令也没有问题。

此外,我已通过--prod命令将此this tutorial中的PWA内容添加到我的应用中。

如何解决此错误?任何建议将不胜感激。

1 个答案:

答案 0 :(得分:3)

今天我为这个错误苦了一个小时。

我的问题在 ngsw-config.json 中。我的文件不是有效的json。

错误stacktrace不能清楚地指向文件。
确保该文件对Tenor528所指的jsonlint.com有效。