undici: Unexpected token on class private field check with in operator
Bug Description
The issue arises from undici@6.7.0
, which is believed to be caused by the PR https://github.com/nodejs/undici/pull/2743/files#diff-7d87ea2cf8b3c20e25ac9a785c4ae7603f4a8c3d7bf3a80f5fb46265f0dba078R776
⨯ ./node_modules/undici/lib/web/fetch/util.js
Module parse failed: Unexpected token (608:63)
| // 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.`);
| }
Import trace for requested module:
./node_modules/undici/lib/web/fetch/util.js
./node_modules/undici/lib/web/fetch/index.js
./node_modules/undici/index.js
Reproducible By
The issue can be replicated in any Next.js project by simply upgrading undici to version 6.7.0
Expected Behavior
Run without error
Logs & Screenshots
Environment
Additional context
About this issue
- Original URL
- State: closed
- Created 4 months ago
- Comments: 24 (20 by maintainers)
Hey @fersan96 @HelaGone.
swc
in Next.js doesn’t fully support the transformation of private properties and methods. I am using a temporary solution by integratingbabel-loader
with required plugins. Given that transforming code can slow down building times, onlyundici
packages is included by the loader.A small change for webpack config in
next.config.js
like belowAlso I reported these plugins to Next.js https://github.com/vercel/next.js/discussions/30174#discussioncomment-8793544, feel free to leave a comment and probably could speed up that.
Yep, I’m hitting the same error too. I’ll flag this with the Next.js folks and dig into it. It’s holding us up on updating undici for now. Thanks for the help! I’ll post any updates here and avoid any duplicate issues popping up.
@nicole0707 Hello, i hope you’re doing well, i would like to know what happend with this problem , is solved?
Definitely a problem with Next.js parser
https://github.com/tsctx/nextjs-private-field-in-operator-bug
Valid point seems like an issue with Nextjs and the clear context should be provided on how
undici
is used since Nextjs has a lot of moving parts as compared to working with Node plainly.This is not a fundamental solution. Please report it Next.js and have the problem fixed.
Increasing the number of variables and adding try statements leads to extra overhead.
These are already slow and do not want to add even this small change.
This workaround is a violation of the specification because it throws an error with a false value.
Please provide a minimal viable code example.