Service Worker script does not exist at the given path
See original GitHub issueHello, we have a storybook running in a subdirectories (for PRs and also one stable version). Msw was not working out of the box for this setup, but then I used #75 setup.
serviceWorker: {
url: `blabla/blabla-storybook/${STORYBOOK_SHA ?? "latest"}/mockServiceWorker.js`,
}
Issues is, we are still getting an error that file does not exist in the path. But when I click on the link in the error message, I am taken to mockServiceWorker.js
, so it obliviously exist in the location.
Uncaught (in promise) Error: [MSW] Failed to register a Service Worker for scope ('https://cdn.blabla.no/') with script ('https://cdn.blabla.no/blabla/blablabla-storybook/${commitSHA}/mockServiceWorker.js'): Service Worker script does not exist at the given path.
Did you forget to run "npx msw init <PUBLIC_DIR>"
We are using React with CRA and latest version of storybook.
Is anyone able to help with this, please? I have no clue at this point what might be the issue.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Service Worker Registration issue - Stack Overflow
This script inside the page is just unable to locate /ServiceWorker.js and could be due to 1 thing out of 2.
Read more >Browser - Getting Started - Mock Service Worker Docs
Browser. Setup. Mock Service Worker operates client-side by registering a Service Worker responsible for requests interception.
Read more >Service Workers - W3C
If objectMap [ serviceWorker ] does not exist, then: Let serviceWorkerObj be a new ServiceWorker in environment 's Realm, and associate it with ......
Read more >Using Service Workers - Web APIs | MDN
The path to your service worker file is not written correctly — it needs to be written relative to the origin, not your...
Read more >Service workers - web.dev
Not all browsers support service workers. Even when present your service worker won't be available on first load or while it's waiting to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just ran into this as well.
Work around is to tell MSW where to look for the file. One gotcha is you’ll likely want to have it be different for github pages vs running locally.
https://msw-sb.vercel.app/?path=/story/guides-getting-started--page#configuring-msw https://mswjs.io/docs/api/setup-worker/start#serviceworker
So, I kinda have the same problem. I have a SignIn View that mocks the login request at the stories in the Storybook. If I run it local, it works as expected, but it won’t work at my GitHub repository as it can’t find the mockServiceWorker.js file.
My application: https://guissimatheus.github.io/design-system-react My repo: https://github.com/guissimatheus/design-system-react
If you go to the browser network tab, you can see the msw get request url https://guissimatheus.github.io/mockServiceWorker.js with status code 404. I can access the worker file at https://guissimatheus.github.io/design-system-react/mockServiceWorker.js
I dunno how I can config my project to change the url and get the mock to work on GitHub.