Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadableStream cannot be properly polyfilled in this engine #475

Closed
davidtaboas opened this issue Nov 2, 2023 · 5 comments
Closed

ReadableStream cannot be properly polyfilled in this engine #475

davidtaboas opened this issue Nov 2, 2023 · 5 comments

Comments

@davidtaboas
Copy link

davidtaboas commented Nov 2, 2023

Using msw 2.0.2 I'm getting the following error:

 DataCloneError: Transferring of ReadableStream cannot be properly polyfilled in this engine
        at throwUnpolyfillable ([root_project]/node_modules/core-js/modules/web.structured-clone.js:127:9)
        at tryToTransfer ([root_project]/node_modules/core-js/modules/web.structured-clone.js:579:9)
        at structuredClone ([root_project]/node_modules/core-js/modules/web.structured-clone.js:622:17)
        at cloneBody ([root_project]/node_modules/undici/lib/fetch/body.js:282:21)
        at cloneResponse ([root_project]/node_modules/undici/lib/fetch/response.js:319:24)
        at HttpResponse.clone ([root_project]/node_modules/undici/lib/fetch/response.js:259:28)
        at globalThis.fetch ([root_project]/node_modules/@mswjs/interceptors/lib/node/interceptors/fetch/index.js:92:46)
        at processTicksAndRejections (node:internal/process/task_queues:95:5)

If i change in this line

const responseClone = mockedResponse.clone()

to this, works properly:

const responseClone = new Response(mockedResponse);
@kettanaito
Copy link
Member

Hey, @davidtaboas. Thanks for reporting this.

Please, could you share a reproduction repository for this? It looks like you are running your code in an environment that doesn't correctly implement the global Fetch API (not sure why core-js is even needed here). I cannot help much without the way to reproduce this.

@davidtaboas
Copy link
Author

@kettanaito ok. i will try it.

I'm using msw in a jsdom environment with jest, using undici to polyfill fetch.

@kettanaito
Copy link
Member

Take a look at the Jest+MSW usage example. It may help you spot what may be off.

Why do you need to polyfill fetch? What version of Node.js are you using? Make sure to use Node.js v18+ with MSW 2.0.

@davidtaboas
Copy link
Author

@kettanaito I did, thanks.

But it was no help. However, I removed "core-js" import from my jest.polyfills.js and now it seems to work properly. I will double check a few more times. Meanwhile this issue can still closed.

Thanks!

@kettanaito
Copy link
Member

The issue is that Jest depends on core-js anyway. Although they are grabbing global.structuredClone, it appears it's already polyfilled by core-js at that moment of access.

https://github.com/jestjs/jest/pull/12631/files#diff-7e6b39bebf54c704e027085672211430b8241b080e103d997757bcea915d2041R102

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants