Edge-function failing to build

Here is my edge function.

https://github.com/n-ce/ytify/blob/basic-info-edge-function/netlify/edge-functions/basicInfo.ts

I have used every single configuration I could find to solve the issue but the build never passes!

11:25:43 PM: TypeError: Cannot read properties of undefined (reading 'FinalizationRegistry')
11:25:43 PM:     at node_modules/undici/lib/core/connect.js (file:///tmp/tmp-5775-mzkGt2rgbEK6/chunk-Z2CA2UJE.js:5661:16)
11:25:43 PM:     at __require2 (file:///tmp/tmp-5775-mzkGt2rgbEK6/chunk-CSNBRKUJ.js:33:50)
11:25:43 PM:     at node_modules/undici/lib/client.js (file:///tmp/tmp-5775-mzkGt2rgbEK6/chunk-Z2CA2UJE.js:6360:26)
11:25:43 PM:     at __require2 (file:///tmp/tmp-5775-mzkGt2rgbEK6/chunk-CSNBRKUJ.js:33:50)
11:25:43 PM:     at node_modules/undici/index.js (file:///tmp/tmp-5775-mzkGt2rgbEK6/chunk-Z2CA2UJE.js:16659:18)
11:25:43 PM:     at __require2 (file:///tmp/tmp-5775-mzkGt2rgbEK6/chunk-CSNBRKUJ.js:33:50)
11:25:43 PM:     at file:///tmp/tmp-5775-mzkGt2rgbEK6/chunk-G5SAEFOD.js:30:29

The FinalizationRegistry is part of undici.
The weird part is undici shouldn’t be required at all since I have enforced native fetch as per the module docs and uses node 22 in build settings. Getting Started | YouTube.js

undici is a Node.js core module, so not sure why you find it weird. undici is how fetch works in Node.js.

As far as the solution is concerned, I linked the thread and it has the solution. You didn’t mention anything about it working or not for you:

The solution didn’t work. I tried it on both the main.ts file and the edge-function file.

I checked your recent deploys and don’t see a failed build. Did you resolve it?

It’s on the basic-info-edge-function branch

Yeah I was aware of that branch, but I did not see any deploys from that branch on your site which is why I asked.

Anyways, the issue seems to be solvable by patching undici directly. I modified your build command (on my test site) to:

npm run build && sed -i -e '1iglobalThis.global = globalThis\' ./node_modules/undici/lib/core/connect.js

Basically, I’m adding the same line that I asked others in that thread, except this time I’m adding the line directly in undici insted of your code. The site then deploys successfully.

Actually a deploy never succeeded from that branch that’s why it was not there.
But now it works, thanks!