#2006·msw

MSW fails to start Mock because worker update() fails.

Author: lazpitCreated Jan 30, 2024Updated May 13, 2026
Labelsbugscope:browserneeds:triage

Prerequisites

Environment check

  • I'm using the latest msw version
  • I'm using Node.js version 18 or higher

Browsers

Chromium (Chrome, Brave, etc.), Firefox

Reproduction repository

https://codesandbox.io/p/devbox/msw-react-xx1c8

Reproduction steps

Can't make a reproduction repository, it depends if my backend is accessible. If backend is running, MSW mock starts and do his job. MSW fails to start mock with SetupWorker.start() when server is not reachable.

To reproduce, I have to stop my backend that serves assets and bundle.js resources.

Current behavior

The function that find existing registration of the service worker is trying to update it and returns fetch error below because service-worker.js resources is not accessible.

image image

getWorkerInstance.ts :

if (existingRegistration) { // When the Service Worker is registered, update it and return the reference. return existingRegistration.update().then(() => { return [ getWorkerByRegistration( existingRegistration, absoluteWorkerUrl, findWorker, ), existingRegistration, ] }) }

I'm asking, why do we need to call update() on existingRegistration before returning worker instance if worker is active ?

Expected behavior

Suggestion:

  • Add an option in StartOptions interface to bypass update if not needed.
  • Try update() but catch error and return worker instance from registration if active.