question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FEATURE REQUEST] Import external dependencies in Service Worker

See original GitHub issue

It seems you cannot import anything that is not local to the service-worker folder, and that is not an ES6 module. The config for rollup does not include any plugins to allow importing of CJS or AMD modules, and there is no way to change that config from the outside.

Use case: would want to use libs like localForage or in this case idb-keyval inside a service worker to queue requests while offline, as using IDB directly is a bit cumbersome and localStorage is not available. But for sure there will be other use cases as well.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
dadleyycommented, Apr 11, 2018

FWIW I was able to get this working by using the rollup-plugin-node-resolve package like this.

1reaction
eshtadccommented, Dec 12, 2018

Looks valid and intriguing. Could you pull together a PR that can be tested in some various scenarios?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Import a dependency to a service worker - Stack Overflow
1 Answer 1 · Use ES module imports as a build-time signal to a bundler, like Rollup/webpack/esbuild, to include code in a final...
Read more >
workbox-window - Chrome Developers
A module that helps with registering a service worker, managing updates, and responding to lifecycle events.
Read more >
Using Web Workers - Web APIs - MDN Web Docs
This makes it easier for workers to keep track of where their dependencies are. Importing scripts and libraries. Worker threads have access to...
Read more >
Service worker configuration - Angular
When the ServiceWorker handles a request, it checks asset groups in the order in which they appear in ngsw-config.json . The first asset...
Read more >
Angular 5 Service Worker - Medium
The Angular Service Worker functionality is provided by the module ... @angular/service-worker is installed as part of the dependencies.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found