mswjs / msw

Industry standard API mocking for JavaScript.
https://mswjs.io
MIT License
15.97k stars 519 forks source link

TypeError: Cannot create proxy with a non-object as target or handler in 2.6.0 #2342

Closed boldurean closed 2 weeks ago

boldurean commented 3 weeks ago

Prerequisites

Environment check

Node.js version

20.12.0

Reproduction repository

https://codesandbox.io/p/devbox/lrh2rd

Reproduction steps

  1. change msw version to 2.4.11 and run npm test - test passes
  2. change msw version to 2.6.0 and run npm test - test fail

Current behavior

TypeError: Cannot create proxy with a non-object as target or handler
 ❯ _WebSocketInterceptor.setup node_modules/.pnpm/@mswjs+interceptors@0.36.7/node_modules/@mswjs/interceptors/src/interceptors/WebSocket/index.ts:70:28
 ❯ _WebSocketInterceptor.apply node_modules/.pnpm/@mswjs+interceptors@0.36.7/node_modules/@mswjs/interceptors/src/Interceptor.ts:130:10
 ❯ SetupServerApi.listen node_modules/.pnpm/msw@2.6.0_@types+node@22.8.5_typescript@5.4.5/node_modules/msw/src/node/SetupServerCommonApi.ts:129:26
 ❯ test.setup.js:6:10
      4| 
      5| beforeAll(() => {
      6|   server.listen({
       |          ^
      7|     onUnhandledRequest(request) {
      8|       console.log("Unhandled %s %s", request.method, request.url);

Expected behavior

All test work pass as before.

Afsoon commented 3 weeks ago

I have reported the same error in the interceptors repository, and I have opened a PR to fix it https://github.com/mswjs/interceptors/pull/669. TL;DR: My findings was, they fixed an error for NextJS, but introduced an error for non NextJS projects.

boldurean commented 3 weeks ago

I have reported the same error in the interceptors repository, and I have opened a PR to fix it mswjs/interceptors#669. TL;DR: My findings was, they fixed an error for NextJS, but introduced an error for non NextJS projects.

I would expect simple test will catch it up :|

stevensacks commented 2 weeks ago

Broken for Remix project, as well.

custardcream98 commented 2 weeks ago

can't use msw on tests due to this issue.

kettanaito commented 2 weeks ago

I wish we wouldn't have to do these shenanigans. Having a global property descriptor with a getter that returns undefined is a broken implementation on the framework's side and they mustn't do that. I've already opened a pull request to Next.js to fix that (their issue is different), I didn't expect other frameworks to have this.

Will adjust the interceptor predicate, keeping it sane, hopefully.

kettanaito commented 2 weeks ago

This has been fixed in @mswjs/interceptors@0.36.8 (release notes). We can now handle all sorts of property descriptor combinations.

Re-install your dependencies to pull the latest version of this transient dependency to get the fix.