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

@clerk/remix v4.0.12 RequestInit: duplex option is required when sending a body. #3440

Closed
4 tasks done
jtparrett opened this issue May 24, 2024 · 12 comments
Closed
4 tasks done

Comments

@jtparrett
Copy link
Contributor

jtparrett commented May 24, 2024

Preliminary Checks

Reproduction

https://github.com/jtparrett/rcdriftuk-website

Publishable key

pk_live_Y2xlcmsucmNkcmlmdC51ayQ

Description

This issue only happens in production on vercel, this issue DOES NOT HAPPEN LOCALLY.

I have included the production repo just because the issue only happens in production on vercel.

The problem is with any remix action that uses getAuth() will give the error below regarding a duplex option on the body.

The error happens when using node 20 or node 18. I've also tried updating every possible package.

Please see file: app/routes/events.$id.tsx -> action

Steps to reproduce:

  1. Create a remix action which uses getAuth()
  2. Fire the action using a remix component

Expected behavior:
The getAuth method should return the user

Actual behavior:
The getAuth method has the following error

TypeError: RequestInit: duplex option is required when sending a body.
    at new Request (node:internal/deps/undici/undici:5096:19)
    at new ClerkRequest (/var/task/node_modules/@clerk/backend/dist/internal.js:2273:5)
    at createClerkRequest (/var/task/node_modules/@clerk/backend/dist/internal.js:2313:54)
    at loadOptions (/var/task/node_modules/@clerk/remix/dist/ssr/loadOptions.js:34:63)
    at getAuth (/var/task/node_modules/@clerk/remix/dist/ssr/getAuth.js:32:60)
    at action5 (file:///var/task/build/index.js:3030:26)
    at Object.callRouteAction (/var/task/node_modules/@remix-run/server-runtime/dist/data.js:37:22)
    at commonRoute.action (/var/task/node_modules/@remix-run/server-runtime/dist/routes.js:63:69)
    at actualHandler (/var/task/node_modules/@remix-run/router/dist/router.cjs.js:4218:14)
    at /var/task/node_modules/@remix-run/router/dist/router.cjs.js:4230:27

Environment

System:
    OS: macOS 14.3
    CPU: (8) arm64 Apple M2
    Memory: 71.30 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.0 - ~/.nvm/versions/node/v20.11.0/bin/node
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.0/bin/npm
  Browsers:
    Chrome: 125.0.6422.76
    Safari: 17.3
  npmPackages:
    @clerk/remix: ^4.0.12 => 4.0.12 
    @clerk/themes: ^2.1.2 => 2.1.2 
    @pandacss/dev: ^0.38.0 => 0.38.0 
    @prisma/client: ^5.9.1 => 5.13.0 
    @remix-run/css-bundle: ^2.9.2 => 2.9.2 
    @remix-run/dev: ^2.9.2 => 2.9.2 
    @remix-run/eslint-config: ^2.9.2 => 2.9.2 
    @remix-run/node: ^2.9.2 => 2.9.2 
    @remix-run/react: ^2.9.2 => 2.9.2 
    @remix-run/serve: ^2.9.2 => 2.9.2 
    @types/leaflet: ^1.9.4 => 1.9.12 
    @types/pluralize: ^0.0.33 => 0.0.33 
    @types/react: ^18.2.20 => 18.3.1 
    @types/react-dom: ^18.2.7 => 18.3.0 
    @vercel/analytics: ^1.1.1 => 1.2.2 
    date-fns: ^2.30.0 => 2.30.0 
    eslint: ^8.38.0 => 8.57.0 
    isbot: ^3.6.8 => 3.8.0 
    leaflet: ^1.9.4 => 1.9.4 
    pluralize: ^8.0.0 => 8.0.0 
    prisma: ^5.9.1 => 5.13.0 
    react: ^18.2.0 => 18.3.1 
    react-dom: ^18.2.0 => 18.3.1 
    react-icons: ^5.0.1 => 5.2.0 
    react-leaflet: ^4.2.1 => 4.2.1 
    react-markdown: ^9.0.1 => 9.0.1 
    react-tiny-popover: ^8.0.4 => 8.0.4 
    tiny-invariant: ^1.3.1 => 1.3.3 
    typescript: ^5.1.6 => 5.4.5 
    zod: ^3.22.4 => 3.23.6
@jtparrett jtparrett added the needs-triage A ticket that needs to be triaged by a team member label May 24, 2024
@briardg
Copy link

briardg commented May 26, 2024

Hello,

I have the same issue, and it is not happening inside the Remix Loader but only in the action.

My version of node is the same.

I also added the Vercel recommendation using @vercel/remix instead of @remix-run/node
and vite config import { vercelPreset } from "@vercel/remix/vite";

But nothing helped

@briardg
Copy link

briardg commented May 27, 2024

@jtparrett I have found a way around the issue in case you are interested.

I thought it was weird that in the loader it works but not in the action,
So I dived inside Clerk code and realized they kind of piggy bag on our request.

So I tried to recreate a request that should work basically like in Loaders a get request with headers as this is where the Auth information is saved.

const generateNewRequestForClerk = (request: Request) => {
  const originalRequest = request.clone();
  const newRequestInit = {
    method: "GET", // Change the method to GET
    headers: new Headers(originalRequest.headers), // Copy headers from the original request
  };

  // Remove content-type header as it's not needed for GET and may cause issues
  newRequestInit.headers.delete("Content-Type");

  // Instantiate the new request without the body attribute
  return new Request(originalRequest.url, newRequestInit);
};


  const auth = await getAuth({
    ...args,
    request: generateNewRequestForClerk(args.request),
  });

Try it out and please tell me if it is working on your side too? 🙏

@linear linear bot added confirmed and removed needs-triage A ticket that needs to be triaged by a team member labels May 27, 2024
@LekoArts
Copy link
Member

@octoper will look into this!

@briardg
Copy link

briardg commented May 28, 2024

@octoper will look into this!

I can be available for any live coding meeting if needed

@jtparrett
Copy link
Contributor Author

briardg

Thanks for this! Yes, that fix also worked in my case 👍 using it as a workaround for now.

@frago12
Copy link

frago12 commented Jun 14, 2024

@briardg thank you for the workaround, worked well on my end too

@LekoArts
Copy link
Member

This was fixed with #3495 👍

@ainoya
Copy link

ainoya commented Jun 21, 2024

Hello. I'm using clerk/remix on Cloudflare Pages, and when using getAuth within an ActionFunction, it seems to generate a new error from the code that was fixed in the PR #3495 🤔 The workaround provided seems to prevent the error from occurring.

TypeError: Cannot set property duplex of #<_Request> which has only a getter
    at patchRequest (.../node_modules/@clerk/remix/dist/ssr/utils.js:115:26)

@arminnaimi
Copy link

Hello. I'm using clerk/remix on Cloudflare Pages, and when using getAuth within an ActionFunction, it seems to generate a new error from the code that was fixed in the PR #3495 🤔 The workaround provided seems to prevent the error from occurring.


TypeError: Cannot set property duplex of #<_Request> which has only a getter

    at patchRequest (.../node_modules/@clerk/remix/dist/ssr/utils.js:115:26)

I just started a new project two days ago and I get the same error running on regular Node.js.

@nsb
Copy link

nsb commented Jun 28, 2024

This was fixed with #3495 👍

But this unfortunately introduced a regression. Discussion on Discord here https://discord.com/channels/856971667393609759/1253975184818573313

@arminnaimi I have reported this bug. Hopefully they will fix it soon. In the meantime you can just downgrade to the previous version of @clerk/remix.

@octoper
Copy link
Member

octoper commented Jul 1, 2024

Thanks you for reporting that I will take a look at it today!

@octoper
Copy link
Member

octoper commented Jul 3, 2024

Hey!

We have released a fix for the regression that was introduced in #3495, you can upgrade to the latest version of the Remix SDK and it will be resolved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants