undici icon indicating copy to clipboard operation
undici copied to clipboard

Module parse failed: Unexpected token (874:57) undici/lib/web/fetch/util.js

Open neysimoes opened this issue 2 years ago • 14 comments

Bug Description

 ⨯ ./node_modules/undici/lib/web/fetch/util.js
Module parse failed: Unexpected token (874:57)
|       // 5. If object is not a default iterator object for interface,
|       //    then throw a TypeError.
>       if (typeof this !== 'object' || this === null || !(#target in this)) {
|         throw new TypeError(
|           `'next' called on an object that does not implement interface ${name} Iterator.`

Reproducible By

import { setGlobalDispatcher, ProxyAgent } from "undici";

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
const dispatcher =  new ProxyAgent('http://test.com');
setGlobalDispatcher(dispatcher);

Environment

Ubuntu 22.04 LTS Node v20.12.1 NextJS 14.2.1

neysimoes avatar Apr 15 '24 17:04 neysimoes

Duplicate of #3122

Uzlopak avatar Apr 15 '24 17:04 Uzlopak

Duplicate of #3122

#3122 is this.

neysimoes avatar Apr 15 '24 18:04 neysimoes

@KhafraDev should we fix this?

ronag avatar Apr 15 '24 19:04 ronag

No strong opinion. I don't think we should be providing workarounds for libraries that don't understand valid syntax, but this will throw a TypeError regardless if the private prop is accessed if this is bound to something else.

KhafraDev avatar Apr 15 '24 19:04 KhafraDev

I update the NextJS version to "14.2.1" and solve the problem.

Actually, I don't think we should fix it. It only happens on an outdated version of nextjs, seems like it's already been fixed upstream.


This is actually a duplicate of #2923.

KhafraDev avatar Apr 15 '24 19:04 KhafraDev

Correction: The problem was not resolved with the Next update. I had changed the file inside node_modules and had forgotten about it.

@KhafraDev

neysimoes avatar Apr 16 '24 18:04 neysimoes

@neysimoes I am facing the same issue. Can you please explain a bit in detail as to how you fixed it? My code is almost the same as you wrote and error message is also the same.

NextJS version: 14.1.4 Node version: 20.11.0

AdityaParashar24 avatar Jul 17 '24 22:07 AdityaParashar24

This is still not fix in NexJs, but the problem relies on undici

Rolando-Barbella avatar Aug 20 '24 23:08 Rolando-Barbella

There is fundamentally nothing for us to fix in undici.

https://github.com/vercel/next.js/discussions/30174#discussioncomment-8793544

KhafraDev avatar Aug 20 '24 23:08 KhafraDev

Same issue here. I cannot use cheerio because of that.

ContrapunctusII avatar Aug 29 '24 13:08 ContrapunctusII

Again, this is not an issue in undici. This is valid syntax.

Uzlopak avatar Aug 29 '24 13:08 Uzlopak

FWIW, when you have issues with dependencies and Next.js, it is almost always not the dependencies issue. Next.js does a lot of automatic magic including transpiling, bundling, and more.

Use the Next.js config to exclude non-compatible dependencies either via fields like https://nextjs.org/docs/app/api-reference/next-config-js/serverExternalPackages or modifying the webpack config https://nextjs.org/docs/app/api-reference/next-config-js/webpack

Ethan-Arrowood avatar Aug 29 '24 15:08 Ethan-Arrowood

If you have this issue, you can force the undici version to be 5.28.4 to solve this issue, as mentioned here: https://github.com/nodejs/undici/discussions/3010#discussioncomment-9581353

truca avatar Sep 21 '24 18:09 truca

if you are using firebase then shift to latest version these fix my issue . if not downgrade the version I think is the best solution

sayedhasan7 avatar Oct 20 '25 18:10 sayedhasan7