-
Notifications
You must be signed in to change notification settings - Fork 27.4k
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
[NEXT-1188] [13.4.x] ReferenceError: TextEncoder is not defined #49397
Comments
I encountered this exact same error on my team when running Jest tests. The error for us, appears to be coming through Apollo Client @apollo/client@3.7.14 Like @ribeaud the fix was to downgrade to v13.3.4. I bisected through it and for us, the error is introduced through this PR which removes node-fetch as a fallback and goes straight to undici. I reverted the commit Otherwise, setting the global TextEncoder did get me a step further as suggested here, but ran into further issues clearImmediate is not defined
/next.js/packages/next/dist/compiled/undici/index.js:1:82074) The below didn't work for me but may work for someone else. For me the Apollo client would never return data // jest.setup.ts
global.clearImmediate = jest.fn() My info npx next info
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 22.4.0: Mon Mar 6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000
Binaries:
Node: 18.15.0
npm: 9.5.0
Yarn: N/A
pnpm: 7.28.0
Relevant packages:
next: 13.4.5-canary.0
eslint-config-next: 13.4.5-canary.0
react: 18.2.0
react-dom: 18.2.0
typescript: 4.8.2 |
This happens sometimes to us in production
|
this class seems to be imported from the polyfill, which maybe is failing to build under some some circumstances
|
It is clear that the problem relates to Jest only. The deployed application works correctly on our side. |
Could it be that the fetch polyfill is not complete and miss |
I am confirm this bug exist on I am downgrade to |
having this issue as well |
Has there been any movement on this? I'm encountering it as well |
https://caniuse.com/mdn-api_textencoder This API has been available in browsers for a long time, added in Chrome 38 which was published on 15th of August 2014. Looking at the stacktraces the reports are related to jsdom and somehow running Next.js internals with JSDOM (not sure how that setup would work, but the stacktrace is quite clear that it is using jsdom). JSDOM doesn't have TextEncoder it seems: jsdom/jsdom#2524. Is anyone else running into this that is not in the JSDOM environment? |
For those of you experiencing this error when:
Try adding this to the top of your test file: /**
* @jest-environment node
*/ See the jest docs for more. |
@Kevin-McGonigle, do you mean to add it at the top of each file? Is there another way to add it to the jest config once time? |
@MenaiAla If most of your tests are for code executed in the node runtime, then going the opposite direction of setting the
to the top of tests for files where the code under test is typically executed in the browser might be the less painful route. This, and my previous comment, is only applicable when the cause of this error is due to the mix up in runtimes. |
Thank you @Kevin-McGonigle. |
Verify canary release
Provide environment information
❯ npx next info Operating System: Platform: darwin Arch: x64 Version: Darwin Kernel Version 22.4.0: Mon Mar 6 21:00:17 PST 2023; root:xnu-8796.101.5~3/RELEASE_X86_64 Binaries: Node: 18.14.0 npm: 9.3.1 Yarn: 1.22.19 pnpm: N/A Relevant packages: next: 13.4.1 eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0
Which area(s) of Next.js are affected? (leave empty if unsure)
No response
Link to the code that reproduces this issue
https://gitlab.com/biomedit/next-widgets/
To Reproduce
npm i && npm run test
Describe the Bug
Since v13.4.x, our test suites started to throw following error:
If we roll back to v13.3.4, the tests are green.
Somehow I have the impression that #49053 introduced the problem on our side but I am not sure 100% (I went through all the changes listed in the changelog).
Here is the MR where the problem started to appear.
The MR did succeed because I reverted Next.js to v13.3.4.
Expected Behavior
Tests should be green.
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
NEXT-1188
The text was updated successfully, but these errors were encountered: