Skip to content

ReferenceError: ReadableStream is not defined #1934

Answered by OscarJVD
OscarJVD asked this question in Q&A
Discussion options

You must be logged in to vote

Solution

Add ReadeableStream next to TextEncoder and our jest.pollyfills.js will look so:

// jest.polyfills.js
/**
 * @note The block below contains polyfills for Node.js globals
 * required for Jest to function when running JSDOM tests.
 * These HAVE to be require's and HAVE to be in this exact
 * order, since "undici" depends on the "TextEncoder" global API.
 *
 * Consider migrating to a more modern test runner if
 * you don't want to deal with this.
 */

const { TextDecoder, TextEncoder, ReadableStream } = require("node:util")

Object.defineProperties(globalThis, {
  TextDecoder: { value: TextDecoder },
  TextEncoder: { value: TextEncoder },
  ReadableStream: { value: ReadableStream },
})

Replies: 7 comments 24 replies

Comment options

You must be logged in to vote
18 replies
@martinnajjar12
Comment options

@kellyrmilligan
Comment options

@akashmakde
Comment options

@akashmakde
Comment options

@halilibrahimcelik
Comment options

Answer selected by kettanaito
Comment options

You must be logged in to vote
3 replies
@surfer19
Comment options

@narensulegai
Comment options

@bgourlie
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@DaleSalcedo
Comment options

@martinnajjar12
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@mattlean
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet