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: 4 comments 17 replies

Comment options

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

@pedroSoaresll
Comment options

@kettanaito
Comment options

@kettanaito
Comment options

@nathanhannig
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
1 reply
@DaleSalcedo
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