undici
undici copied to clipboard
undici/lib/fetch/headers.js: Unexpected token (300:44)
Bug Description
Getting this error on serverless project.
Error: Parsing file .../test_server/node_modules/undici/lib/fetch/headers.js: Unexpected token (300:44)
at Deps.parseDeps (.../test_server/node_modules/module-deps/index.js:519:15)
at getDeps (.../test_server/node_modules/module-deps/index.js:447:44)
at .../test_server/node_modules/module-deps/index.js:430:38
at ConcatStream.<anonymous> (.../test_server/node_modules/concat-stream/index.js:37:43)
at ConcatStream.emit (node:events:532:35)
at ConcatStream.emit (node:domain:475:12)
at finishMaybe (.../test_server/node_modules/readable-stream/lib/_stream_writable.js:630:14)
at endWritable (.../test_server/node_modules/readable-stream/lib/_stream_writable.js:638:3)
at ConcatStream.Writable.end (.../test_server/node_modules/readable-stream/lib/_stream_writable.js:594:41)
at DuplexWrapper.onend (.../test_server/node_modules/readable-stream/lib/_stream_readable.js:577:10)
at Object.onceWrapper (node:events:639:28)
at DuplexWrapper.emit (node:events:532:35)
at DuplexWrapper.emit (node:domain:475:12)
at endReadableNT (.../test_server/node_modules/readable-stream/lib/_stream_readable.js:1010:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
Reproducible By
Here is an example repository for the issue: https://github.com/BRoy98/undici-serverless
Note: It happens only when serverless-plugin-optimize is being used to optimize the handlers.
Steps to reproduce:
- Clone the repository
- Install dependencies:
yarn install - Invoke the function:
yarn invoke
To disable the optimize plugin, uncomment #L10 on serverless.yml: https://github.com/BRoy98/undici-serverless/blob/b15fb3ad50c1a2f81d1391636bc06a1794684622/serverless.yml#L10
Expected Behavior
Should run without error.
Environment
Tested on: MacOS monterey 12.4 (21F79) and Ubuntu Latest (github actions) Node v16.14.0 and Node v14.19.3
Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.
I think this is another issue with using ??= again?
https://github.com/nodejs/undici/blob/966a54ff80993573d1baab5999ce258ccc0e7ec9/lib/fetch/headers.js#L300
Can we add a test?
Isn't that a problem with the module-deps module or one of its dependencies? It has to support this syntax.
It's been a frequent problem when bundling undici on node 14 using webpack, etc.
See #1397 (actually this exact issue) and https://github.com/nodejs/undici/pull/1318
Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.
Updated description with a reproducible example repository. Please check.
Digging in a little bit, it is the parser https://github.com/acornjs/acorn that seems not to support Logical nullish assignment (??=)
I'm going to investigate a little more and eventually open an issue about this.
Error:
SyntaxError: Unexpected token (300:44)
at _class.pp$4.raise (/workspace/undici-serverless/node_modules/acorn/dist/acorn.js:2931:15)
at _class.pp.unexpected (/workspace/undici-serverless/node_modules/acorn/dist/acorn.js:700:10)
at _class.pp$3.parseExprAtom (/workspace/undici-serverless/node_modules/acorn/dist/acorn.js:2328:12)
...
...
at endReadableNT (/workspace/undici-serverless/node_modules/readable-stream/lib/_stream_readable.js:1010:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
It seems we need to wait for these 2 issues to resolve #https://github.com/browserify/detective/issues/88 #https://github.com/browserify/acorn-node/issues/17
If you want you can open a PR to remove ?? in undici.
think that acorn/detective should be updated to support ?? will help more ppl that use ?? elsewhere that don't just use undici
??= assignment converted