Module parse failed: Unexpected token (874:57) undici/lib/web/fetch/util.js
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
Duplicate of #3122
Duplicate of #3122
#3122 is this.
@KhafraDev should we fix this?
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.
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.
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 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
This is still not fix in NexJs, but the problem relies on undici
There is fundamentally nothing for us to fix in undici.
https://github.com/vercel/next.js/discussions/30174#discussioncomment-8793544
Same issue here. I cannot use cheerio because of that.
Again, this is not an issue in undici. This is valid syntax.
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
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
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