remix-run / react-router

Declarative routing for React
https://reactrouter.com
MIT License
53.2k stars 10.32k forks source link

[Bug]: ReferenceError: TextEncoder is not defined #12363

Open remarkablemark opened 4 hours ago

remarkablemark commented 4 hours ago

What version of React Router are you using?

7.0.1

Steps to Reproduce

https://github.com/remarkablemark/mui-template/pull/1082

git clone https://github.com/remarkablemark/mui-template.git
cd mui-template
git checkout dependabot/npm_and_yarn/react-router-dom-7.0.1
npm install
npm test

I tried replacing react-router-dom with react-router but got the same error

Expected Behavior

Jest tests pass with latest react-router version

Actual Behavior

Jest tests failing with error:

      ReferenceError: TextEncoder is not defined

        2 | import type { ReactElement, ReactNode } from 'react';
        3 | import { Provider } from 'react-redux';
      > 4 | import { createMemoryRouter, RouterProvider } from 'react-router-dom';
          | ^
        5 | import { resetActions, store } from 'src/store';
        6 |
        7 | export { store };

        at Object.<anonymous> (node_modules/react-router/dist/production/index.js:8368:15)
        at Object.<anonymous> (node_modules/react-router-dom/dist/index.js:39:38)
        at Object.<anonymous> (test/helpers.tsx:4:1)
        at Object.<anonymous> (test/setupTests.ts:7:1)
timdorr commented 2 hours ago

What versions of Node, jest, and jsdom are you using? It sounds like you have something out of date.

remarkablemark commented 1 hour ago

I'm using:

Dependency Version
Node.js 20.18.0
Jest 29.7.0
jsdom 20.0.3

Let me try upgrading Node.js from 20 to 22


Update 1: upgrading Node.js didn't fix it, but I noticed that jsdom is currently v25 so let me try to update that in my project

Update 2: I tried upgrading jest-environment-jsdom from 29.7.0 to 30.0.0-alpha.6 but it still failed locally for me. I can confirm the jsdom version did go up:

$ npm ls jsdom
└─┬ jest-environment-jsdom@30.0.0-alpha.6
  ├─┬ @jest/environment-jsdom-abstract@30.0.0-alpha.6
  │ └── jsdom@25.0.1
  └── jsdom@22.1.0

Update 3: I set package.json overrides to ensure jsdom is 25 but tests still failed locally