question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

vite dev server: infinte refresh loop when using msw

See original GitHub issue

Describe 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:

  1. Go to https://github.com/vuejs/create-vue
  2. create a vite app
  3. npm install msw --save-dev
  4. 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");
});
  1. npm run dev

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rathaxcommented, Feb 23, 2022

manually clearing the service worker from both firefox and chrome seem to have resolved the issue.

0reactions
dankremniovcommented, Mar 11, 2022

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found