remix-run / indie-stack

The Remix Stack for deploying to Fly with SQLite, authentication, testing, linting, formatting, etc.
https://remix.run/stacks
MIT License
1.13k stars 315 forks source link

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

Closed petecartwright closed 1 month ago

petecartwright commented 4 months ago

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

yes

Steps to Reproduce

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 commented 1 month ago

@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 commented 1 month ago

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 commented 1 month ago

yep, I can't reproduce this now either. :thinking: :thinking: :thinking: 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!