-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
refactor: rejig hyper-connect
usage of fetch
#566
Comments
This was a doozy to debug. I've filed an issue with Vercel vercel/vercel#9690 Firstly, this error only occurs on deployments to Vercel, it does not happen locally. So debug iterations involved committing and pushing to GitHub, waiting on Vercel to deploy, then looking at the function logs in Vercel. I was able to replicate this on all combinations of Node 16 and 18 and NextJS 12 and 13. I set up an endpoint that called directly into an instance of From the stacktrace, it seemed that a Request was somehow being passed into a
fetch(new Request('https://foo.bar', {...})) // this is valid, according to the spec
fetch ('https://foo.bar', { ... }) // this is also valid, according to the spec Both of these usages of So I started looking into where There are tons of references to I created two identical Lambdas and deployed them onto Vercel: One passing a import type { NextApiRequest, NextApiResponse } from 'next';
import { fetch, Request } from 'undici'
export default async function (_req: NextApiRequest, res: NextApiResponse): Promise<void> {
return fetch('https://jsonplaceholder.typicode.com/todos/1')
.then(res => res.json())
.then(res.json)
.catch((err) => {
console.error(err);
res.json(err);
});
} And one passing import type { NextApiRequest, NextApiResponse } from 'next';
import { fetch, Request } from 'undici'
export default async function (_req: NextApiRequest, res: NextApiResponse): Promise<void> {
return fetch(new Request('https://jsonplaceholder.typicode.com/todos/1'))
.then(res => res.json())
.then(res.json)
.catch((err) => {
console.error(err);
res.json(err);
});
} Notice that these lambdas don't reference The first Lambda succeeds. The second Lambda fails, with the error we were getting from our This proves that NextJS is overwriting SolutionI have filed an issue on Vercel. They are seemingly overwriting a module resolution as part of their cloud environment. And because it's as the Node module resolution level, there doesn't seem to be a way to get around it without changing our own code. I suspect that will take a while for the Vercel team to address, so I have altered the behavior of |
I have been struggling with this issue for 1 month now, any idea how we can push forward a solution? Initially I solved the problem by forcing Next.JS to use node-fetch instead of undici, but Next.JS had an update which dropped node-fetch entirely in favour of undici and the workaround I was using is not helpful anymore. I created related issues on undici, vercel and next.js in hopes to drive momentum but this issue seems to be extremely slow to resolve. I tried replicating locally, sadly I was not able to. It's such a tricky edge case that seems to only error on deployments on |
@kaloyanBozhkov I see your comment on the Vercel issue I filed. It's a different error than what we were seeing, but could very well be caused by the same underlying thing: Vercel overwriting I had to dig into I can't speak to your specific issue, other than suggest that you follow the same approach: dig into your code and your dependency code ie. |
There seems to be a new issue when using
hyper-connect
on Vercel, more specifically passing aRequest
object toundici
, which is whathyper-connect
does.See vercel/vercel#9690 for background
While that issue is being addressed, I am going to have to update
hyper-connect
to -- not do that. I think I can take theRequest
object and pull off it's parts and then pass it tofetch
The text was updated successfully, but these errors were encountered: