Skip to content

Service worker register don't fetch the ngsw.json correctly #8516

@jvitor83

Description

@jvitor83

Bug Report or Feature Request (mark with an x)

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

Versions.

Angular CLI: 1.6.0-beta.0
Node: 8.9.0
OS: win32 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.33
@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.3
typescript: 2.4.2
webpack: 3.8.1

Repro steps.

ng new project --service-worker
cd project
ng build --prod --base-href=/project/

replace the line 16 of app.module.ts to:
environment.production ? ServiceWorkerModule.register('/project/ngsw-worker.js') : []
(this is another bug #8515)

then

Publish the dist folder to a web server with a base url /project/
Ex: http://localhost/project/

The log given by the failure.

At console:

Uncaught (in promise) Error: Manifest fetch failed!
    at Driver.fetchLatestManifest (ngsw-worker.js:2147)
    at <anonymous>
fetchLatestManifest @ ngsw-worker.js:2147
Promise rejected (async)
onMessage @ ngsw-worker.js:1814
Driver.scope.addEventListener @ ngsw-worker.js:1755

At network of chrome devtools it gives 404 since can't found http://localhost/ngsw.json?ngsw-cache-bust=0.32248277017838034.

Desired functionality.

The right address of fetch should be http://localhost/project/ngsw.json?ngsw-cache-bust=0.32248277017838034

Mention any other details that might be useful.

At line 2141 of ngsw-worker.js file, it should consider the base-href.

const res = await this.safeFetch(this.adapter.newRequest('/ngsw.json?ngsw-cache-bust=' + Math.random()));

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions