-
Notifications
You must be signed in to change notification settings - Fork 12k
ServiceWorker register generated by cli with base-href don't works #8515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@alxhub Could you investigate/answer this? Seems like using |
@alxhub We need your help over here! |
hello @jvitor83 can you help out, I have the same problem, I use angular-cli 1.6.7 failed to load service worker to register :4200/ngsw-worker.js:-Infinity -- |
@hansl - I am also facing the same issue. Any release plan for this? |
Same problem with @angular/cli: 1.7.0 I'm trying to publish a PWA using github pages and always got 404 when trying to get the I'm using to publish it a command to automate the process- |
I fix the problem by hand.... Just open the file |
@zmazouzi service worker don't work with |
Currently, when we add the service-worker(e.g.
But if we build the app with
The path of According to the PWCat (and my trial), this change works well. |
@u-ryo did you try the scenario where the user never know about your app, then he go to it from a link where it is inside a deeper route like: 'http://localhost/basehref/somecomponent/anothercomponent/' ? I not have tested, but it is my guess. |
@gkalpak Will the fix be available for Angular 6? |
Don’t see fix on 6 yet. Still has to use workaround ./ ServiceWorkerModule.register('./ngsw-worker.js', { enabled: environment.production }) |
@Ploppy3, the issue is not in Angular, it is in the boilerplate that the cli generates. -ServiceWorkerModule.register('./ngsw-worker.js', { enabled: environment.production })
+ServiceWorkerModule.register('.ngsw-worker.js', { enabled: environment.production }) |
@xmlking ./ngsw-worker.js is not working for me. Can you share your project configs? |
|
To solve this issue angular/angular-cli#8515
…ke the service worker use an absolute path instead of a relative path as it should
Hi, It worked for me but It doesn't work in offline mode what shall I do? thanks |
|
It is not clear to me (neither from the screenshots, nor from the description) what the problem is. |
@gkalpak basically the service worker is registered, but it don't recognize my page, or mi index, as a cacheable. My url, that point to my index, is |
As I said before, I can't be of much help without a reproduction. |
@u-ryo I spent some hours trying to figure out the problem. And you solutions worked with different base href then "/" in that case we have to make ServiceWorkerModule.register('./ngsw-worker.js', { enabled: environment.production }) relative. Thank you very much you are the man! |
A tiny-bit unrelated but if anyone happens to find this issue when facing similar problems, here's my journey: And it turned out (Thanks to this question) that Service Worker registration is broken as of angular-cli platformBrowserDynamic()
.bootstrapModule(AppModule)
.then(() => {
if ('serviceWorker' in navigator && environment.production) {
navigator.serviceWorker.register('./ngsw-worker.js');
}
})
.catch(console.error); Also don't forget to modify the By the way is this a bug? I feel like it should ignore the last forward slash. This is correct ...
"scope": "/",
"start_url": "/foo/",
... |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug Report or Feature Request (mark with an
x
)Versions.
Repro steps.
then
Publish the dist folder to a web server with a base url /project/
Ex: http://localhost/project/
The log given by the failure.
Failed to fetch
ngsw-worker.js
at chrome devtoolsDesired functionality.
Fetch
ngsw-worker.js
at chrome devtools and service-worker works!Mention any other details that might be useful.
At line 16 of
app.module.ts
generated by cli:the register is starting with
/
which make the fetch start from http://localhost/If is changed to
./
it will works, but i don't test if the first request to a sub-component can confuse this solution, because the first access would be http://localhost/project/somecomponent/, and the register can try to get from http://localhost/project/somecomponent/ngsw-worker.jsMy guess is that
ServiceWorkerModule.register
could include the base-path by default, then it could solve this problem definitely.The text was updated successfully, but these errors were encountered: