Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs don't explain MSW setup, users get console errors looking for mockServiceWorker.js #291

Closed
petecartwright opened this issue Jul 20, 2024 · 3 comments

Comments

@petecartwright
Copy link

Have you experienced this bug with the latest version of the template?

yes

Steps to Reproduce

  • follow stack setup guide
  • run npm run dev
  • navigate around app
  • check terminal console, see 404s for mockServiceWorker.js
Screenshot 2024-07-20 at 11 43 10 AM

Expected Behavior

Ideally there should be no 404s in the console

Actual Behavior

MSW requires users to run npx msw init public --save to create the service worker it uses for mocking. The default npm run dev runs with the mock server on, so msw checks for that file on some (most?) http requests.

Adding instructions to run that command to the docs should cover this use case - I'll open a PR soon to do that for discussion.

@MichaelDeBoey
Copy link
Member

MichaelDeBoey commented Oct 3, 2024

@petecartwright I can't seem to reproduce the problem you're explaining here.
I can just run npm run dev and look around in the app without any problem.

Tagging @kettanaito (the creator/maintainer of MSW) to know if we would need to add the created public/mockServiceWorker.js file or not

@kettanaito
Copy link

Hey, folks!
You need to run msw init if you want to use MSW in the browser. To my best knowledge, this stack uses MSW primarily for third-party API mocking during integration testing, which runs in Node.js. Thus, there was never the need to generate the worker script via msw init.

You can learn more about using MSW in the browser here: https://mswjs.io/docs/integrations/browser.

@petecartwright
Copy link
Author

yep, I can't reproduce this now either. 🤔 🤔 🤔 I'm 95% sure I did with a new repo at the time I filed this, but ¯_(ツ)_/¯

I could have sworn I found was triggering the browser mocking at the time, but I sure don't see it now.

Sorry for the false alarm, closing this and the PR.

@kettanaito big fan of msw btw!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants