Skip to content

onRequest options are not handled properly in nodejs 20.13.1 #37

@czechaj

Description

@czechaj

I used this package in my nextjs project (14.2.17). I liked the logic behind the project and it worked fine in my project. but then I switched back to another PC with nodejs@20.13.1 installed and somehow my functions that contain @fetch throw the following error:

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) at eval (webpack-internal:///(rsc)/./node_modules/.pnpm/next@14.2.17_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/lib/patch-fetch.js:306:111) at eval (webpack-internal:///(rsc)/./node_modules/.pnpm/next@14.2.17_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/lib/trace/tracer.js:134:36) at NoopContextManager.with (webpack-internal:///(rsc)/./node_modules/.pnpm/next@14.2.17_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7062) at ContextAPI.with (webpack-internal:///(rsc)/./node_modules/.pnpm/next@14.2.17_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:518) at NoopTracer.startActiveSpan (webpack-internal:///(rsc)/./node_modules/.pnpm/next@14.2.17_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18093) at ProxyTracer.startActiveSpan (webpack-internal:///(rsc)/./node_modules/.pnpm/next@14.2.17_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18854) at eval (webpack-internal:///(rsc)/./node_modules/.pnpm/next@14.2.17_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/lib/trace/tracer.js:116:103) at NoopContextManager.with (webpack-internal:///(rsc)/./node_modules/.pnpm/next@14.2.17_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7062) at ContextAPI.with (webpack-internal:///(rsc)/./node_modules/.pnpm/next@14.2.17_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:518) at NextTracerImpl.trace (webpack-internal:///(rsc)/./node_modules/.pnpm/next@14.2.17_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/lib/trace/tracer.js:116:28) at patched (webpack-internal:///(rsc)/./node_modules/.pnpm/next@14.2.17_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/lib/patch-fetch.js:233:41) at betterFetch (webpack-internal:///(rsc)/./node_modules/.pnpm/@better-fetch+fetch@1.1.15/node_modules/@better-fetch/fetch/dist/index.js:573:24) at async $fetch (webpack-internal:///(rsc)/./node_modules/.pnpm/@better-fetch+fetch@1.1.15/node_modules/@better-fetch/fetch/dist/index.js:488:12) at async getCustodianAccount (webpack-internal:///(rsc)/./src/server/actions/custodian-account-application.ts:19:29) at async CustodianAccountPage (webpack-internal:///(rsc)/./src/app/(account)/saklama-hesabim/page.tsx:21:34)

When I followed the stack trace, I found out that this function was causing the error:

export const getCustodianAccount = async ({
  token,
}: {
  token?: string | null;
}): Promise<CustodianAccount> => {
  const { data, error } = await $fetch("/customer/custodian-account", {
    async onRequest(options) {
      options.headers = {
        ...options.headers,
        Authorization: token ?? "",
      };
      return options;
    },
  });

  if (error) {
    throw error;
  }
  return data;
};

I can confirm that the function gets the token properly, but somehow it throws the error mentioned. When I debugged the problem, I realized that the nodejs version was 22...* on the computer where I was running without problems, so I installed nodejs v22.14.0 on the computer where I was getting the error, restarted the project and the error went away.

I searched this repository to see if this issue has been mentioned before, but I couldn't find it. I don't know exactly how this package is incompatible with version 20.13.1 of nodejs, but it would be nice if it could be added to the documentation until this is resolved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions