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

@astrojs/vercel: 2.3.5 breaks API endpoints #5568

Closed
1 task
Ehesp opened this issue Dec 9, 2022 · 14 comments · Fixed by #5587
Closed
1 task

@astrojs/vercel: 2.3.5 breaks API endpoints #5568

Ehesp opened this issue Dec 9, 2022 · 14 comments · Fixed by #5587
Assignees
Labels
- P5: urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority)

Comments

@Ehesp
Copy link

Ehesp commented Dec 9, 2022

What version of astro are you using?

1.6.14

Are you using an SSR adapter? If so, which one?

Vercel

What package manager are you using?

npm

What operating system are you using?

Mac

Describe the Bug

The @astrojs/vercel adapter is breaking API endpoints on vercel when using 2.3.5. On 2.3.4 they work as expected.

I've got a deployment running in the reproduction link below on Vercel, as you can see if you look at network, any requests to /api are failing with the same error:

ERROR	Unhandled Promise Rejection 	{"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"TypeError: response.body.getReader is not a function","reason":{"errorType":"TypeError","errorMessage":"response.body.getReader is not a function","stack":["TypeError: response.body.getReader is not a function","    at setResponse (file:///var/task/node_modules/@astrojs/vercel/dist/serverless/request-transform.js:109:32)","    at Server.handler (file:///var/task/node_modules/@astrojs/vercel/dist/serverless/entrypoint.js:22:11)","    at processTicksAndRejections (node:internal/process/task_queues:96:5)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: TypeError: response.body.getReader is not a function","    at process.<anonymous> (file:///var/runtime/index.mjs:1194:17)","    at process.emit (node:events:539:35)","    at process.emit (node:domain:475:12)","    at emit (node:internal/process/promises:140:20)","    at processPromiseRejections (node:internal/process/promises:274:27)","    at processTicksAndRejections (node:internal/process/task_queues:97:32)"]}
Unknown application error occurred
Runtime.Unknown

Looks like this commit from @JuanM04 is the issue.

For clarity, the endpoint failing does a basic response:

export const post: APIRoute = async ({ request }) => {
  const { idToken } = (await request.json()) as { idToken: string };

  if (!idToken) {
    return new Response(null, {
      status: 200,
      headers: new Headers({
        'Set-Cookie': cookie.serialize('session', '', {
          expires: new Date(0), // Deletes the cookie
        }),
      }),
    });
  }

  const expiryDys = 5; // Expires in 5 days
  const expires = 60 * 60 * 24 * expiryDys * 1000;
  const session = await createSessionToken(idToken, expires);

  return new Response(null, {
    status: 200,
    headers: new Headers({
      'Set-Cookie': cookie.serialize('session', session, {
        maxAge: expires,
        path: '/',
        httpOnly: false, // Allows the cookie to be read by the client and sent via fetch
      }),
    }),
  });
};

Link to Minimal Reproducible Example

https://zapp-r4q76tpec-invertase.vercel.app/

Participation

  • I am willing to submit a pull request for this issue.
@matthewp matthewp self-assigned this Dec 9, 2022
@matthewp matthewp added the - P5: urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority) label Dec 9, 2022
@matthewp
Copy link
Contributor

matthewp commented Dec 9, 2022

So sorry to hear this, paging @JuanM04 in case he knows what's going on. I'll take a look myself too.

This is the only change in 2.3.5: #5514

@JuanM04
Copy link
Contributor

JuanM04 commented Dec 9, 2022

Ohhhh, I think I know what's happening. getReader is only supported in Node v16. @Ehesp, are you using Node v16 or above? Is the Vercel project set to use Node v16 or v18?

@matthewp
Copy link
Contributor

matthewp commented Dec 9, 2022

Can we do a fallback for those on Node 14?

@JuanM04
Copy link
Contributor

JuanM04 commented Dec 9, 2022

@matthewp I will see what I can do. First, I'll wait to @Ehesp response to see if upgrading Node fixes it

@Ehesp
Copy link
Author

Ehesp commented Dec 9, 2022

image

Hmm, version is set to Node 16 on Vercel.

@pilcrowonpaper
Copy link
Contributor

Should this issue be prioritized over #5489?

@matthewp
Copy link
Contributor

Yes, regressions are prioritized.

@pilcrowonpaper
Copy link
Contributor

pilcrowonpaper commented Dec 10, 2022

@matthewp I mean like aren't these the same issue? So, should I close #5489 over this issue?

@matthewp
Copy link
Contributor

They might be the same issue! Let's leave them open for now and after we have this fixed if you wouldn't mind checking to see if it fixes yours as well.

@pilcrowonpaper
Copy link
Contributor

Oh, the error message is ever slightly so different, my bad!

@JuanM04
Copy link
Contributor

JuanM04 commented Dec 12, 2022

Sorry for the late response, I wasn't available. I've identified the issue and I'm solving it. Meanwhile, @Ehesp, upgrading to Node v18 solves it.

@Ehesp
Copy link
Author

Ehesp commented Dec 12, 2022

Thanks - I'm unable to upgrade at the moment, but I have locked to 2.3.4 for the time being.

@JuanM04
Copy link
Contributor

JuanM04 commented Dec 12, 2022

@Ehesp I've made a PR. Could you try with @astrojs/vercel@next--set-cookie?

@savicaleksa
Copy link

@Ehesp I've made a PR. Could you try with @astrojs/vercel@next--set-cookie?

I can confirm that this also fixes the issue with @astrojs/image and sharp not working on vercel ssr.
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P5: urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants