Closed sebastianbuechler closed 4 months ago
Hi, @sebastianbuechler. There seems to be a few things going on.
First, you are using msw/browser
, which, I think, Bun has nothing to do with..? Sorry, I'm not aware if Bun ships the entire devkit that allows spawning apps in the browser too. Even if it does, that cannot be connected with the Interceptors library where we're in.
Secondly, the error strongly suggests that the msw
package is still old (1.x). Run npm i msw@latest
, clear any dependency cache, and re-run your app. I'm fairly certain the error will be fixed then.
If not, please submit a reproduction repository where I can take a look. We generally don't promise Bun compatibility because promising Node.js compatibility is enough (Bun aims to be compatible with Node.js). If there are any issues with MSW itself, I will be happy to find them and fix them. Thanks!
Hi, @sebastianbuechler. There seems to be a few things going on.
First, you are using
msw/browser
, which, I think, Bun has nothing to do with..? Sorry, I'm not aware if Bun ships the entire devkit that allows spawning apps in the browser too. Even if it does, that cannot be connected with the Interceptors library where we're in.Secondly, the error strongly suggests that the
msw
package is still old (1.x). Runnpm i msw@latest
, clear any dependency cache, and re-run your app. I'm fairly certain the error will be fixed then.If not, please submit a reproduction repository where I can take a look. We generally don't promise Bun compatibility because promising Node.js compatibility is enough (Bun aims to be compatible with Node.js). If there are any issues with MSW itself, I will be happy to find them and fix them. Thanks!
Hi @kettanaito, thanks four your reply!
You're absolutely right. It was a mix up of the old package still being present. I think my monorepo setup was not properly configured for updating dependencies. Now it seems to work with msw/browser
, as I use MSW for mocking during development and import it that way.
Thanks for the hint and your work for MSW 👍
I used MSW v1.3.2 with bun (v1.1.17) successfully and now I wanted to upgrade to v2 (i.e. to v2.3.4) like this:
index.tsx
And without handlers I can see that MSW is enabled by observing in the console:
[MSW] Mocking enabled.
However, when I now add an example handler from the docs like this it breaks: handlers.ts
Error:
handlers.ts:4 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'get') at handlers.ts:4:8
If I try a GraphQL handler it works as expected:
The
mockServiceWorker.js
file is in the public directory and I can correctly access it when my application is served. Why ishttp
not defined? Is it because of Bun?