mswjs / msw

Seamless REST/GraphQL API mocking library for browser and Node.js.
https://mswjs.io
MIT License
15.75k stars 508 forks source link

The currently registered Service Worker has been generated by a different version of MSW (undefined) #2119

Open kettanaito opened 6 months ago

kettanaito commented 6 months ago

Prerequisites

Environment check

Browsers

No response

Reproduction repository

Reproduction steps

  1. Set up MSW in a browser.
  2. Perform an unhandled request.

Current behavior

entry.client.tsx:20 [MSW] The currently registered Service Worker has been generated by a different version of MSW (undefined) and may not be fully compatible with the installed version.

It's recommended you update your worker script by running this command:

  • npx msw init <PUBLIC_DIR>

You can also automate this process and make the worker script update automatically upon the library installations. Read more: https://mswjs.io/docs/cli/init.

Expected behavior

Should print the actual MSW version, not (undefined).

robdodson commented 5 months ago

@kettanaito I have seen this issue and was wondering if it's just because an unhandled request is happening, or if the msw version is also out of date?

We have a monorepo of SPAs with a root package.json, and then each directory holds an SPA with its own public dir. For example:

.
├── appA
│   ├── public
│       └── mockServiceWorker.js
├── appB
│   ├── public
│       └── mockServiceWorker.js
├── package.json

The SPAs are all sharing the same mockServiceWorker.js file with a PACKAGE_VERSION of 2.2.13, which matches the version in our root package.json. But I was wondering how the mockServiceWorker file checks its version and if it needs to be told where to find the package.json?