Skip to content

TypeError: Could not convert argument of type symbol to string when setting headers with Headers object in Node.js v22.2.0 #53069

Description

@elhaddajiOtmane

Version

v22.2.0

Platform

Microsoft Windows NT 10.0.22631.0 x64

Subsystem

idk :undici package (dependency used by Next.js)

What steps will reproduce the bug?

Create a new Next.js project using the latest version (as of writing, it's Next.js 13.2.4).
In one of the pages , import the Headers object from undici and try to set headers,
let headers = new Headers();
headers.set('Access-Control-Allow-Credentials', true);
headers.set('Access-Control-Allow-Origin', '*');
headers.set('x-auth-token',' process.env.EXAMPLE.TOKEN');

How often does it reproduce? Is there a required condition?

The issue reproduces consistently when running the above steps with Node.js version 22.2.0.

What is the expected behavior? Why is that the expected behavior?

The expected behavior is for the Headers object to correctly accept and set the provided header key-value pairs without throwing any errors. This is the expected behavior because the Headers object should handle string values for both header keys and values according to the documentation and specifications.

What do you see instead?

TypeError: Could not convert argument of type symbol to string.
at webidl.converters.DOMString (node:internal/deps/undici/undici:1977:15)
at webidl.converters.ByteString (node:internal/deps/undici/undici:1982:35)
at Object.record<ByteString, ByteString> (node:internal/deps/undici/undici:1894:30)
at webidl.converters.HeadersInit (node:internal/deps/undici/undici:3424:67)
at new Headers (node:internal/deps/undici/undici:3278:36)

Additional information

"undici": "5.23.0",

Activity

  1. elhaddajiOtmane commented on May 20, 2024

    @elhaddajiOtmane
    Author

    Everything is working fine with the Headers object when using Node.js 20.1.0

  2. KhafraDev commented on May 20, 2024

    @KhafraDev
    Member

    Fixed in #53034

  3. alexsorokoletov commented on Jul 7, 2024

    @alexsorokoletov

    Hi!

    I am having this issue (or a similar error stack) on Azure on Linux with Node v20.14.0
    Would appreciate any thoughts or ideas what could be triggering this error

    2024-07-07T08:46:44.2040292Z TypeError: Could not convert argument of type symbol to string.
    2024-07-07T08:46:44.2040990Z     at webidl.converters.DOMString (node:internal/deps/undici/undici:1977:15)
    2024-07-07T08:46:44.2041027Z     at webidl.converters.ByteString (node:internal/deps/undici/undici:1982:35)
    2024-07-07T08:46:44.2041057Z     at Object.record<ByteString, ByteString> (node:internal/deps/undici/undici:1894:30)
    2024-07-07T08:46:44.2041087Z     at webidl.converters.HeadersInit (node:internal/deps/undici/undici:3424:67)
    2024-07-07T08:46:44.2041114Z     at new Headers (node:internal/deps/undici/undici:3278:36)
    2024-07-07T08:46:44.2041142Z     at /home/site/wwwroot/.next/server/chunks/638.js:1:37936
    2024-07-07T08:46:44.2041168Z     at /home/site/wwwroot/.next/server/chunks/638.js:1:47490
    2024-07-07T08:46:44.2041223Z     at NoopContextManager.with (/agents/nodejs/node_modules/@opentelemetry/api/build/src/context/NoopContextManager.js:25:19)
    2024-07-07T08:46:44.2041252Z     at ContextAPI.with (/agents/nodejs/node_modules/@opentelemetry/api/build/src/api/context.js:60:46)
    2024-07-07T08:46:44.2041283Z     at Tracer.startActiveSpan (/agents/nodejs/node_modules/@opentelemetry/sdk-trace-base/build/src/Tracer.js:121:32)
    
  4. KhafraDev commented on Aug 3, 2024

    @KhafraDev
    Member

    @Bx1 I would recommend reading the Code of Conduct. Your comment regarding undici is neither welcome nor helpful.

  5. Bx1 commented on Aug 3, 2024

    @Bx1

    @KhafraDev I would recommend you to read my answer again to comprehend. This is one of many ways to bypass undici errors. Nevertheless your comment is off topic, so rethink twice what you write.

  6. deleted a comment from Bx1 on Aug 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionIssues asking questions about Node.js.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions