angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Service worker missing config error has confusing path

Open StephenFluin opened this issue 9 years ago • 4 comments

Bug Report or Feature Request (mark with an x)

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

Versions

Node: 8.4.0
OS: linux x64
Angular: 5.0.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router, service-worker

@angular/cli: 1.6.0-beta.0
@angular-devkit/build-optimizer: 0.0.32
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.35
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.0-beta.0
@schematics/angular: 0.1.2
typescript: 2.4.2
webpack: 3.8.1

Repro steps.

ng new <x> cd x add ServiceWorkerModule and register a SW ng build -prod

Error thrown

Error: Expected to find an ngsw-config.json configuration file in the
                                application root. Either provide one or disable Service Worker
                                build support in angular-cli.json.

Desired functionality.

Show the user WHERE they need to create the file (application root sounds like /src/app). Also would be nice to have cleaner whitespace usage.

Error: Expected to find an ngsw-config.json configuration file in the /src folder. Either provide one or disable Service Worker in .angular-cli.json.

StephenFluin avatar Nov 14 '17 19:11 StephenFluin

CONFIGURATION: Angular CLI: 1.6.0-beta.0 Node: 8.9.0 OS: win32 x64 Angular: 5.0.2 ... animations, common, compiler, compiler-cli, core, forms ... http, language-service, platform-browser ... platform-browser-dynamic, platform-server, router ... service-worker

@angular/cdk: 5.0.0-rc0 @angular/cli: 1.6.0-beta.0 @angular/material: 5.0.0-rc0 @angular-devkit/build-optimizer: 0.0.33 @angular-devkit/core: 0.0.20 @angular-devkit/schematics: 0.0.36 @ngtools/json-schema: 1.1.0 @ngtools/webpack: 1.9.0-beta.0 @schematics/angular: 0.1.5 typescript: 2.4.2 webpack: 3.8.1

MAJOR BUG WITH USING NEW SERVICE-WORKER

Based on Angular Connect 2017 video. Coded app.module.ts with the following but did not load the service worker after issuing ng build --prod environment.production ? ServiceWorkerModule.register('/ngsw-worker.js') : [],

Works: platformBrowserDynamic().bootstrapModule(AppModule) .then (() => { if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/ngsw-worker.js'); }

FIREFOX ISSUE WITH FIREBASE DATA USING SERVICE-WORKER: My POC works fine with Chome but fails to show any data with Firebox and the service workder activated. When I disable the service worker then Firefox data appears from the Firebase (Realtime and Firestore) databases.

I'm using latest firebase and angularfire2 libs. The Realtime app is based on Firebase codelab "Cloud functions for Firebase, I copied the code that manages the push notifications (messaging) from Firebase. (reported to Firebase that the codelab was out of date with AngularFire2 did get push to work). Would love to see better docs on using Angular (latest) with push notify and service-worker combo from Firebase/Firestore.

ngsw-config.json - needs documentation on how to configure for Firebase as well as routing. Noticed issue with routing using service worker. In the past I used the "ng-pwa-tools": "0.0.15" based on the Google i/o video this worked well in the past but no longer works with the new Firebase Firestore lib received an error:

$ ./node_modules/.bin/ngu-sw-manifest --module src/app/app.module.ts Error: Cannot find module 'grpc' at Function.Module._resolveFilename (module.js:536:15) at Function.Module._load (module.js:466:25) at Module.require (module.js:579:17) at require (internal/module.js:11:18) at Object. (C:\Users\MCarbone\Desktop\PWAToo\pwapush-v2\node_modules@firebase\firestore\dist\cjs\src\src\platform_node\grpc_connection.ts:32:14) at Module._compile (module.js:635:30) at Object.Module._extensions..js (module.js:646:10) at Module.load (module.js:554:32) at tryModuleLoad (module.js:497:12) at Function.Module._load (module.js:489:3)

I've been following: Alex Rickabaugh and Maxim Salnikov's talks on PWAs. I'm hoping by ng-conf 2017 PWA's will documented, automated and easy to configure. Also on my wish list is a steamlined process for Angular Universal, push notifications (Angular/Firebase using Firestore) in addition, managing out-of date service-workers.

Many thanks for all the hard work and making Angular a great development platform.

// **************

MINOR BUG:

.angular-cli.json asset "firebase-messaging.sw.js" is not getting copied to dist during ng build --prod call "manifest.json" is.

{ "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "project": { "name": "pwaa" }, "apps": [ { "root": "src", "outDir": "dist", "assets": [ "assets", "favicon.ico", "firebase-messaging-sw.js", "manifest.json" ], ...

Got around this by manually coping to dist folder then firebase-messaging.sw.js worked as expected.

MatteoNY avatar Nov 20 '17 18:11 MatteoNY

@hansl where should it expect it?

kenisteward avatar Nov 23 '17 01:11 kenisteward

@hansl nvm I was going off old docs. I had it in the right place but mine was called ngsw-manifest.json which is what it used to accept not ngsw-config.json. This should definitely be noted in docs.

kenisteward avatar Nov 23 '17 01:11 kenisteward

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.