Requests not properly resolving with axios in the browser
See original GitHub issueDescribe the bug
One the latest version of axios (0.19.2), and with any version >= 0.18.0 of msw any calls to axios.get do not ever resolve the promise. There are no errors in the console, and MSW and networks logs indicate the request was handled correctly
I haven’t had time to make an isolated reproducible case yet, but will try to do so. In my app the request in question is one where I’m not actually mocking anything, just letting it pass through to the server, but I’m not sure that it’s relevant.
Environment
msw: 0.18.0
npm: 6.13.4
Please also provide your browser version. Replicated in Firefox 77.0.1 and Chrome 83.0.4103.61
To Reproduce
Steps to reproduce the behavior:
Should be reproducible with axios code like
axios.get("/foo").then(res=> console.log(res))
Expected behavior
Should log the response out to the console, but instead we never seem to make it inside the then statement. A clear and concise description of what you expected to happen.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top GitHub Comments
@kettanaito yeah everything is working fine. Basically I had one file that had my handler definitions, my worker setup and my server setup. I broke it into 3 seperate files, and ensured that I only imported the one in the bundle used in the browser.
Got a reproduction! https://github.com/AndrewSwerlick/examples.
The gist of it is that it appears if you ever call
setupServer
frommsw/node
in the browser it borks axios. I was trying to consolidate and organize my code by having a single module that exported both anodeSever
and abrowserServer
and then I imported and started the right one depending on the environment I was running in (jest vs browser). I assumed setupServer was side effect free, and nothing would happen until we calledlisten
, but looking at the code it appears that’s not the case.It may be worth modifying the
setupServer
function to include a warning if running in a browser environment, or something like that.