Build Error: TypeError related to FinalizationRegistry in Edge Functions

Maybe it’s smth with the versions,I don’t know.I removed FB totally for now and all started to work

Hello! I tried the solutions below to fix the issue, but the error still persists:

if (typeof global === undefined) {
  globalThis.global = globalThis;
}

I also tested another approach found here: Netlify Answers:

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

Unfortunately, neither of these resolved the problem :frowning:

3:45:17 PM: build-image version: c3449036692ceba113a2b71302d561bccc8b6156 (focal)
3:45:17 PM: buildbot version: 6e5dfadf0eec598d7c9db5c1e005bfa46b6682c0
3:45:17 PM: Fetching cached dependencies
3:45:17 PM: Starting to download cache of 251.0MB
3:45:19 PM: Finished downloading cache in 1.367s
3:45:19 PM: Starting to extract cache
3:45:22 PM: Finished extracting cache in 3.42s
3:45:22 PM: Finished fetching cache in 4.839s
3:45:22 PM: Starting to prepare the repo for build
3:45:23 PM: Preparing Git Reference pull/105/head
3:45:24 PM: Starting to install dependencies
3:45:25 PM: Started restoring cached mise cache
3:45:25 PM: Finished restoring cached mise cache
3:45:26 PM: mise python@3.13.1   install
3:45:26 PM: mise python@3.13.1   download cpython-3.13.1+20241219-x86_64-unknown-linux-gnu-install_only_stripped.tar.gz
3:45:26 PM: mise python@3.13.1   extract cpython-3.13.1+20241219-x86_64-unknown-linux-gnu-install_only_stripped.tar.gz
3:45:26 PM: mise python@3.13.1   python --version
3:45:26 PM: mise python@3.13.1   Python 3.13.1
3:45:26 PM: mise python@3.13.1 ✓ installed
3:45:26 PM: Python version set to 3.13
3:45:27 PM: Collecting pipenv
3:45:28 PM:   Downloading pipenv-2024.4.0-py3-none-any.whl.metadata (19 kB)
3:45:28 PM: Collecting certifi (from pipenv)
3:45:28 PM:   Downloading certifi-2024.12.14-py3-none-any.whl.metadata (2.3 kB)
3:45:28 PM: Collecting packaging>=22 (from pipenv)
3:45:28 PM:   Downloading packaging-24.2-py3-none-any.whl.metadata (3.2 kB)
3:45:28 PM: Collecting setuptools>=67 (from pipenv)
3:45:28 PM:   Downloading setuptools-75.6.0-py3-none-any.whl.metadata (6.7 kB)
3:45:28 PM: Collecting virtualenv>=20.24.2 (from pipenv)
3:45:28 PM:   Downloading virtualenv-20.28.1-py3-none-any.whl.metadata (4.5 kB)
3:45:28 PM: Collecting distlib<1,>=0.3.7 (from virtualenv>=20.24.2->pipenv)
3:45:28 PM:   Downloading distlib-0.3.9-py2.py3-none-any.whl.metadata (5.2 kB)
3:45:28 PM: Collecting filelock<4,>=3.12.2 (from virtualenv>=20.24.2->pipenv)
3:45:28 PM:   Downloading filelock-3.16.1-py3-none-any.whl.metadata (2.9 kB)
3:45:28 PM: Collecting platformdirs<5,>=3.9.1 (from virtualenv>=20.24.2->pipenv)
3:45:28 PM:   Downloading platformdirs-4.3.6-py3-none-any.whl.metadata (11 kB)
3:45:28 PM: Downloading pipenv-2024.4.0-py3-none-any.whl (3.0 MB)
3:45:28 PM:    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.0/3.0 MB 56.1 MB/s eta 0:00:00
3:45:28 PM: Downloading packaging-24.2-py3-none-any.whl (65 kB)
3:45:28 PM: Downloading setuptools-75.6.0-py3-none-any.whl (1.2 MB)
3:45:28 PM:    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 99.6 MB/s eta 0:00:00
3:45:28 PM: Downloading virtualenv-20.28.1-py3-none-any.whl (4.3 MB)
3:45:28 PM:    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.3/4.3 MB 196.8 MB/s eta 0:00:00
3:45:28 PM: Downloading certifi-2024.12.14-py3-none-any.whl (164 kB)
3:45:28 PM: Downloading distlib-0.3.9-py2.py3-none-any.whl (468 kB)
3:45:28 PM: Downloading filelock-3.16.1-py3-none-any.whl (16 kB)
3:45:28 PM: Downloading platformdirs-4.3.6-py3-none-any.whl (18 kB)
3:45:28 PM: Installing collected packages: distlib, setuptools, platformdirs, packaging, filelock, certifi, virtualenv, pipenv
3:45:30 PM: Successfully installed certifi-2024.12.14 distlib-0.3.9 filelock-3.16.1 packaging-24.2 pipenv-2024.4.0 platformdirs-4.3.6 setuptools-75.6.0 virtualenv-20.28.1
3:45:31 PM: Attempting Ruby version 2.7.2, read from environment
3:45:31 PM: Using Ruby version 2.7.2
3:45:32 PM: Started restoring cached go cache
3:45:32 PM: Finished restoring cached go cache
3:45:33 PM: go version go1.19.13 linux/amd64
3:45:34 PM: Using PHP version 8.0
3:45:35 PM: Started restoring cached Node.js version
3:45:36 PM: Finished restoring cached Node.js version
3:45:37 PM: v20.18.1 is already installed.
3:45:37 PM: Now using node v20.18.1 (npm v10.8.2)
3:45:37 PM: Enabling Node.js Corepack
3:45:37 PM: Started restoring cached build plugins
3:45:37 PM: Finished restoring cached build plugins
3:45:37 PM: Started restoring cached corepack dependencies
3:45:37 PM: Finished restoring cached corepack dependencies
3:45:37 PM: No npm workspaces detected
3:45:37 PM: Started restoring cached node modules
3:45:37 PM: Finished restoring cached node modules
3:45:37 PM: Installing npm packages using npm version 10.8.2
3:45:37 PM: npm warn using --force Recommended protections disabled.
3:45:39 PM: added 4 packages, removed 9 packages, changed 2 packages, and audited 1054 packages in 1s
3:45:39 PM: 121 packages are looking for funding
3:45:39 PM:   run `npm fund` for details
3:45:39 PM: found 0 vulnerabilities
3:45:39 PM: npm notice
3:45:39 PM: npm notice New major version of npm available! 10.8.2 -> 11.0.0
3:45:39 PM: npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.0.0
3:45:39 PM: npm notice To update run: npm install -g npm@11.0.0
3:45:39 PM: npm notice
3:45:39 PM: npm packages installed
3:45:39 PM: Successfully installed dependencies
3:45:39 PM: Starting build script
3:45:40 PM: Detected 1 framework(s)
3:45:40 PM: "angular" at version "17.3.9"
3:45:40 PM: Section completed: initializing
3:45:42 PM: ​
3:45:42 PM: Netlify Build                                                 
3:45:42 PM: ────────────────────────────────────────────────────────────────
3:45:42 PM: ​
3:45:42 PM: ❯ Version
3:45:42 PM:   @netlify/build 29.58.1
3:45:42 PM: ​
3:45:42 PM: ❯ Flags
3:45:42 PM:   accountId: 5f672f83d18439031d28980e
3:45:42 PM:   baseRelDir: true
3:45:42 PM:   buildId: 67793b4645c8510008042521
3:45:42 PM:   deployId: 67793b4645c8510008042523
3:45:42 PM: ​
3:45:42 PM: ❯ Current directory
3:45:42 PM:   /opt/build/repo
3:45:42 PM: ​
3:45:42 PM: ❯ Config file
3:45:42 PM:   No config file was defined: using default values.
3:45:42 PM: ​
3:45:42 PM: ❯ Context
3:45:42 PM:   deploy-preview
3:45:42 PM: ​
3:45:42 PM: ❯ Loading plugins
3:45:42 PM:    - @netlify/angular-runtime@2.2.1 from Netlify app
3:45:43 PM: ​
3:45:43 PM: Build command from Netlify app                                
3:45:43 PM: ────────────────────────────────────────────────────────────────
3:45:43 PM: ​
3:45:43 PM: $ npm run build && sed -i -e '1iglobalThis.global = globalThis\' ./node_modules/undici/lib/core/connect.js
3:45:43 PM: > unity@0.0.0 build
3:45:43 PM: > ng build
3:45:44 PM: - Building...
3:46:09 PM: Browser bundles
3:46:09 PM: Initial chunk files     | Names               |  Raw size | Estimated transfer size
3:46:09 PM: main-CTEC64GD.js        | main                |   1.02 MB |               231.18 kB
3:46:09 PM: chunk-CS37UGWO.js       | -                   | 171.06 kB |                41.47 kB
3:46:09 PM: polyfills-EONH2QZO.js   | polyfills           |  33.73 kB |                11.05 kB
3:46:09 PM: styles-RY6KL75Y.css     | styles              |   7.95 kB |                 2.43 kB
3:46:09 PM:                         | Initial total       |   1.23 MB |               286.14 kB
3:46:09 PM: Lazy chunk files        | Names               |  Raw size | Estimated transfer size
3:46:09 PM: chunk-V2GHIPMZ.js       | index-esm           |  29 bytes |                29 bytes
3:46:09 PM: Server bundles
3:46:09 PM: Initial chunk files     | Names               |  Raw size
3:46:09 PM: chunk-MGUAG26S.mjs      | -                   |   1.49 MB | 
3:46:09 PM: server.mjs              | server              |   1.06 MB | 
3:46:09 PM: chunk-EAIOCKTR.mjs      | -                   | 920.09 kB | 
3:46:09 PM: chunk-JQHYCQA6.mjs      | -                   | 523.65 kB | 
3:46:09 PM: polyfills.server.mjs    | polyfills.server    | 231.49 kB | 
3:46:09 PM: chunk-H6KHSOBK.mjs      | -                   |   2.80 kB | 
3:46:09 PM: chunk-W6O7R4GF.mjs      | -                   |   2.25 kB | 
3:46:09 PM: render-utils.server.mjs | render-utils.server | 252 bytes | 
3:46:09 PM: main.server.mjs         | main.server         | 207 bytes | 
3:46:09 PM: Lazy chunk files        | Names               |  Raw size
3:46:09 PM: chunk-RH5DZPDL.mjs      | xhr2                |  11.79 kB | 
3:46:09 PM: chunk-T47DBX76.mjs      | index               | 121 bytes | 
3:46:09 PM: Output location: /opt/build/repo/dist/Unity
3:46:09 PM: Application bundle generation complete. [25.070 seconds]
3:46:09 PM: ​
3:46:09 PM: (build.command completed in 25.8s)
3:46:09 PM: Writing Angular SSR Edge Function ...
3:46:09 PM: Writing Angular SSR Edge Function ...
3:46:09 PM: ​
3:46:09 PM: Edge Functions bundling                                       
3:46:09 PM: ────────────────────────────────────────────────────────────────
3:46:09 PM: ​
3:46:09 PM: Packaging Edge Functions from .netlify/edge-functions directory:
3:46:09 PM:  - angular-ssr
3:46:15 PM: TypeError: Cannot read properties of undefined (reading 'FinalizationRegistry')
3:46:15 PM:     at file:///opt/build/repo/dist/Unity/server/chunk-EAIOCKTR.mjs:2:31273
3:46:15 PM:     at file:///opt/build/repo/dist/Unity/server/chunk-H6KHSOBK.mjs:2:1052
3:46:15 PM:     at file:///opt/build/repo/dist/Unity/server/chunk-EAIOCKTR.mjs:39:10354
3:46:15 PM:     at file:///opt/build/repo/dist/Unity/server/chunk-H6KHSOBK.mjs:2:1052
3:46:15 PM:     at file:///opt/build/repo/dist/Unity/server/chunk-EAIOCKTR.mjs:45:4461
3:46:15 PM:     at file:///opt/build/repo/dist/Unity/server/chunk-H6KHSOBK.mjs:2:1052
3:46:15 PM:     at file:///opt/build/repo/dist/Unity/server/chunk-EAIOCKTR.mjs:94:45
3:46:15 PM: ​
3:46:15 PM: Bundling of edge function failed                              
3:46:15 PM: ────────────────────────────────────────────────────────────────
3:46:15 PM: ​
3:46:15 PM:   Error message
3:46:15 PM:   Could not load edge function at '/opt/build/repo/.netlify/edge-functions/angular-ssr/angular-ssr.mjs'. More on the Edge Functions API at https://ntl.fyi/edge-api.
3:46:15 PM: ​
3:46:15 PM:   Error location
3:46:15 PM:   While bundling edge function
3:46:15 PM: ​
3:46:15 PM:   Resolved config
3:46:15 PM:   build:
3:46:15 PM:     command: npm run build && sed -i -e '1iglobalThis.global = globalThis\' ./node_modules/undici/lib/core/connect.js
    commandOrigin: ui
3:46:15 PM:     environment:
3:46:15 PM:       - CI
3:46:15 PM:       - NPM_FLAGS
3:46:15 PM:       - REVIEW_ID
3:46:15 PM:     publish: /opt/build/repo/dist/Unity/browser
3:46:15 PM:     publishOrigin: ui
3:46:15 PM:   plugins:
3:46:15 PM:     - inputs: {}
3:46:15 PM:       origin: ui
3:46:15 PM:       package: '@netlify/angular-runtime'
3:46:15 PM:   redirects:
3:46:16 PM:     - from: /*
      status: 200
      to: /index.html
3:46:16 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:46:16 PM: Failing build: Failed to build site
3:46:16 PM: Finished processing build request in 58.769s
3:46:16 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)

Can you share your repo?

I’ve sent an invite to the repository for hrishikesh-k. Additionally, the changes related to SSR are in the branch.

I’ve asked the devs to take a look.

1 Like

hey, there is any updates here ?

Hi, did the devs have a chance to look over the error ?