vite dev server: infinte refresh loop when using msw
See original GitHub issueDescribe the bug
running a vite dev server with msw will result in a refresh loop that keeps restarting the vite dev server. The setup did work in the past without issues, so I assume it may have something to do with some changes in a dependency.
Environment
msw: ^0.38.1
nodejs: v16.13.2
- `npm: 8.1.2 up to date Chrome and Firefox
To Reproduce
Steps to reproduce the behavior:
- Go to https://github.com/vuejs/create-vue
- create a vite app
- npm install msw --save-dev
- npx msw init public/ --save 5 setup MSW in main.ts
import { createApp } from "vue";
import { createPinia } from "pinia";
import App from "./App.vue";
import router from "./router";
import { setupWorker, rest } from "msw";
const worker = setupWorker(
// Provide request handlers
rest.get("https://example.com/user/:userId", (req, res, ctx) => {
return res(
ctx.json({
firstName: "John",
lastName: "Maverick",
})
);
})
);
async function prepare() {
return worker.start();
}
prepare().then(() => {
const app = createApp(App);
app.use(createPinia());
app.use(router);
app.mount("#app");
});
- npm run dev
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
reactjs - Vite Reload Loop - Stack Overflow
The issue I'm having is that when I load the client in browser it continuously refreshes, the console saying that vite is connecting,...
Read more >[Solved]-Vite Reload Loop-Reactjs - appsloveworld
I use it as a reverse proxy and here "front" makes reference to my Vue app served by Vite in development mode. By...
Read more >Untitled
Dc foodies, Mortgage with a 670 credit score, Bibigul akhmetova, ... 80 mm pebbles, Stuedahl dagny, Youngmee baik, Srpski vitezovi u srednjem veku, ......
Read more >Thoughts on Storybook? : r/reactjs - Reddit
We use Storybook as part of our dev loop, and it's sped up feature dev. ... Have you tried Storybook with Vite as...
Read more >A curated list of awesome things related to Vite.js - Morioh
electron-vite-template - Electron 13, Vue 3 and TypeScript. Make your desktop development easier. fast-vite-electron - Vue3 + Vite + Electron with esbuild. fast ......
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
manually clearing the service worker from both firefox and chrome seem to have resolved the issue.
@kettanaito, I tried but didn’t manage to reproduce it in a clean repo. However, I managed to fix the issue in the project I was working on. The Next.js app was having a
basePath
set which means that worker’s scope was not root. As soon as I specifically specified root scope and added the required header (as per MSW docs) - the issue disappeared.