If I createServer
with miragejs, WDS (Webpack Dev Server) get disconnected.
if I disable mirages mock server, WDS works I expected.
Here is full call stack of [WDS] Disconnected!
import { mockServer } from './server';
if (process.env.NODE_ENV === "development") {
mockServer({ environment: "development" });
}
ReactDOM.render(
<React.StrictMode>
<Provider store={store}>
<ConnectedRouter history={history}>
<App />
</ConnectedRouter>
</Provider>
</React.StrictMode>,
document.getElementById('root')
);
import { createServer, Response, Model } from 'miragejs';
export const mockServer = ({ environment = 'test' }) => {
createServer({
environment,
routes() {
this.namespace = "api";
this.post('/user/login', (schema, request) => {
return new Response(200, { }, { id: "admin@gmail.com", email: "qwerty", token: "Edovbkeyd2943kd3" });
});
},
});
}
export default mockServer;
I solved this problem by migrating from React Hot Loader
to React Fast Refresh
.
I recommend to read 'Moving towards next step' of React Hot Loader
. React Hot Loader
is slowly replace to React Fast Refresh
.