cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Support import statements in Service Workers

dazy
Making moves

Most major browsers support the use of ECMAScript import statements in the Service Worker by declaring { type: 'module' } when registering the Service Worker script. 

This:

// in main script
navigator.serviceWorker.register("service-worker.js", {
  type: "module",
})

Enables:

// in service-worker.js
import "path/to/this.js"
import { that } from 'path/to/that.js'
import * as theOtherThing from 'path/to/theOtherThing.js'
// ...

Unfortunately Firefox does not support this functionality for Service Workers. This was disappointing because I had intended to package my Service Worker code for a notification-based library as ECMA modules.

A similar feature was implemented for Web Workers two years ago

Is FF actively working on this functionality for Service Workers?

1 REPLY 1

stacyjasper
Making moves

Firefox's lack of support for ECMAScript import statements in Service Workers is indeed frustrating, especially since other major browsers have implemented this functionality. Given that Web Workers gained module support two years ago, it's surprising that Service Workers are still left behind. This limitation makes it difficult to maintain clean, modular code, particularly for use cases like notification-based libraries. Firefox should prioritize adding this feature to stay aligned with modern web development practices. If you're developing with Service www.alexandrialimos.com Workers, consider testing in Chromium-based browsers or checking Mozilla's roadmap for updates.

Thanks!

Type a product name