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

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

Closed
remarkablemark opened this issue Nov 23, 2024 · 3 comments
Closed

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

remarkablemark opened this issue Nov 23, 2024 · 3 comments
Labels

Comments

@remarkablemark
Copy link

remarkablemark commented Nov 23, 2024

What version of React Router are you using?

7.0.1

Steps to Reproduce

remarkablemark/mui-template#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
Copy link
Member

timdorr commented Nov 24, 2024

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

@remarkablemark
Copy link
Author

remarkablemark commented Nov 24, 2024

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
└─┬ [email protected]
  ├─┬ @jest/[email protected]
  │ └── [email protected]
  └── [email protected]

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

@timdorr
Copy link
Member

timdorr commented Nov 24, 2024

It looks like jsdom doesn't implement TextEncoder yet, but there is a PR out there for it.

In the meantime, you can use the same workarounds we do in our test setup.

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

No branches or pull requests

2 participants