Skip to content
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

undici/lib/fetch/headers.js: Unexpected token (300:44) #1479

Closed
BRoy98 opened this issue Jun 1, 2022 · 11 comments · Fixed by #1625
Closed

undici/lib/fetch/headers.js: Unexpected token (300:44) #1479

BRoy98 opened this issue Jun 1, 2022 · 11 comments · Fixed by #1625
Labels
bug Something isn't working

Comments

@BRoy98
Copy link

BRoy98 commented Jun 1, 2022

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

@BRoy98 BRoy98 added the bug Something isn't working label Jun 1, 2022
@mcollina
Copy link
Member

mcollina commented Jun 1, 2022

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.

@KhafraDev
Copy link
Member

I think this is another issue with using ??= again?

this[kHeadersList][kHeadersSortedMap] ??= new Map([...this[kHeadersList]].sort((a, b) => a[0] < b[0] ? -1 : 1))

@mcollina
Copy link
Member

mcollina commented Jun 1, 2022

Can we add a test?

@targos
Copy link
Member

targos commented Jun 1, 2022

Isn't that a problem with the module-deps module or one of its dependencies? It has to support this syntax.

@KhafraDev
Copy link
Member

It's been a frequent problem when bundling undici on node 14 using webpack, etc.

See #1397 (actually this exact issue) and #1318

@BRoy98
Copy link
Author

BRoy98 commented Jun 1, 2022

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.

@avanelli
Copy link
Contributor

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)

@avanelli
Copy link
Contributor

avanelli commented Aug 25, 2022

It seems we need to wait for these 2 issues to resolve
#browserify/detective#88
#browserify/acorn-node#17

@ronag
Copy link
Member

ronag commented Aug 25, 2022

If you want you can open a PR to remove ?? in undici.

@jimmywarting
Copy link
Contributor

think that acorn/detective should be updated to support ??
will help more ppl that use ?? elsewhere that don't just use undici

@avanelli
Copy link
Contributor

??= assignment converted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants