Describe the bug
When importing msw, i.e. Mock Service Worker, version 2, for example ^2.10.2, and running vitest inside a webcontainer or in StackBlitz, I get the following error:
TypeError: Cannot read properties of undefined (reading 'on')
❯ eval node_modules/msw/src/core/ws.ts:111:5
❯ _0x4067db ../../../blitz.6384d811.js:31:819992
❯ _0x3c6779.run ../../../blitz.6384d811.js:31:820730
❯ _0x2d8398 ../../../blitz.6384d811.js:31:835770
❯ _0x5d48ba._evaluate ../../../blitz.6384d811.js:31:836120
❯ _0x5a8db7 ../../../blitz.6384d811.js:31:835395
❯ _0x5a8db7 ../../../blitz.6384d811.js:31:835586
❯ _0x5a8db7 ../../../blitz.6384d811.js:31:835586
Based on the error logs above, it appears that somewhere in this file from msw a call to a function or to instantiate an object, maybe BroadcastChannel or WebSocketHandler is being blocked by webcontainers. As a result, some variable is undefined.
https://github.com/mswjs/msw/blob/main/src/core/ws.ts
Note
Using the previous version of msw, i.e. version 1, for example ^1.3.5, works just fine.
Link to the blitz that caused the error
https://stackblitz.com/edit/stackblitz-webcontainer-api-starter-5tvm1xzj
Steps to reproduce
npm run test
Expected behavior
Using msw inside webcontainers should work without an issue.
Describe the bug
When importing
msw, i.e.Mock Service Worker, version 2, for example^2.10.2, and runningvitestinside awebcontaineror in StackBlitz, I get the following error:Based on the error logs above, it appears that somewhere in this file from
mswa call to a function or to instantiate an object, maybeBroadcastChannelorWebSocketHandleris being blocked bywebcontainers. As a result, some variable isundefined.https://github.com/mswjs/msw/blob/main/src/core/ws.ts
Note
Using the previous version of
msw, i.e. version 1, for example^1.3.5, works just fine.Link to the blitz that caused the error
https://stackblitz.com/edit/stackblitz-webcontainer-api-starter-5tvm1xzj
Steps to reproduce
npm run testExpected behavior
Using
mswinsidewebcontainersshould work without an issue.