Skip to content
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

broken with parcel-bundler 1.10.1 #13

Closed
jthegedus opened this issue Sep 29, 2018 · 2 comments
Closed

broken with parcel-bundler 1.10.1 #13

jthegedus opened this issue Sep 29, 2018 · 2 comments

Comments

@jthegedus
Copy link

This plugin does not work with the latest (at the time of writing) parcel-bundler@1.10.1.

If you update the example and use the default sw.js generation strategy parcel fails on parsing the entry index.html file as it now seems to look for files included with navigator.serviceWorker.register('service-worker.js')

jt@ac:~/projects/parcel-plugin-sw-cache/example$ yarn build
yarn run v1.10.1
$ parcel build --out-dir build src/index.html --public-url /
🚨  /home/jt/projects/parcel-plugin-sw-cache/example/src/service-worker.js: ENOENT: no such file or directory, open '/home/jt/projects/parcel-plugin-sw-cache/example/src/service-worker.js'
Error: ENOENT: no such file or directory, open '/home/jt/projects/parcel-plugin-sw-cache/example/src/service-worker.js'
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
jt@ac:~/projects/parcel-plugin-sw-cache/example
$

It seems if a service worker is to be generated from the output build of parcel then the plugin would need to inject the service worker registration code into the entry html.

@mischnic
Copy link
Owner

mischnic commented Sep 29, 2018

Well, a hacky way to make it work:

		if ('serviceWorker' in navigator) {
			const x = 'service-worker.js';
			navigator.serviceWorker.register(x)
				.then(function(registration) {
					console.log('Registration successful, scope is:', registration.scope);
				})
				.catch(function(error) {
					console.log('Service worker registration failed, error:', error);
				});
		}

The main issue is that the service worker isn't ready yet when parcel doesn't the bundling, because the sw is created based on the files created during bundling. There is no official way to do this.

I've opened an issue with parcel: parcel-bundler/parcel#2080

@jthegedus
Copy link
Author

Cheers for the quick response. Hopefully, there's a better solution when service workers get more complete native support in parcel bundler.

@mischnic mischnic closed this as completed Jun 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants