Msw: Detected outdated Service Worker

Created on 8 Dec 2020  路  5Comments  路  Source: mswjs/msw

Describe the bug

I get this console error in my CI environment.
I used a fixed version of msw, so I guess my service worker file is in line with my library version, but it's just not the latest?

In any case I shouldn't see an error message just because I am not on the latest version of the library.

bug potentially solved

All 5 comments

@florian-milky Try updating MSW and see if the error goes away? I would, to be honest, just update MSW unless there is a reason not to for my particular project.

Hey.

That warning should only show in case your worker file is out of sync with the worker file your _installed_ library version is using. It can get out of sync if you use npx msw init during your CI, for example, since npx pull the latest published package, ignoring your semver range from package.json.

This is a valid scenario for the error, because if the library and worker get out of sync they may start doing things differently, but what's most important鈥攗nexpectedly for your app during tests.

Hot get rid of the error

You can remove the error by either:

  1. Update to the latest version of the library and init the worker once more.
  2. Use your locally installed msw to init the worker: ./node_modules/.bin/msw init instead of npx msw init.

Let me know if that helps.

Thanks for the answers!
It's probably my bad, I downgraded msw because I don't use typescript 4 yet.
I'm gonna check.

Out of curiosity why isn't the worker bundled in the library?

Confirmed it was my bad, I didn't run npx msw init after downgrading. I got a little bit confused by the message saying I should upgrade, it's a corner case that you should downgrade 馃槅
Sorry for the inconvenience

Nothing to be sorry about, @florian-milky. I'm glad we've figured it out.

Out of curiosity why isn't the worker bundled in the library?

Service Worker is sensitive to its scope鈥攁 location on your website where it gets registered. It's a requirement per its specification to serve the worker script as a part of your app. That cannot be done with a worker script that lies in node_modules (at least in a straightforward way). That's why we've decided to make the users copy the worker file and designed a simple CLI to do that faster.

I personally think having a worker script as a physical file on your project makes you feel secure about its contents and logic. It's a rather good thing.

I got a little bit confused by the message saying I should upgrade, it's a corner case that you should downgrade

Not the best experience, I agree. We compute checksum (SHA of the worker script's content) and compare it with the respective SHA of the currently installed library's worker. Detecting whether your worker is ahead/behind of the latest published one isn't that easy with that algorihm.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mainfraame picture mainfraame  路  3Comments

tomalexhughes picture tomalexhughes  路  3Comments

slowselfip picture slowselfip  路  3Comments

lukesmurray picture lukesmurray  路  3Comments

otaciliolacerda picture otaciliolacerda  路  3Comments