angular-cli: 18.1.0: Firebase "Class extends value undefined is not a constructor or null"

Which @angular/* package(s) are the source of the bug?

Don’t known / other

Is this a regression?

Yes

Description

After updating to version 18.1.0. I am getting the following error on ng-serve:

Watch mode enabled. Watching for file changes...
NOTE: Raw file sizes do not reflect development server per-request transformations.
Re-optimizing dependencies because lockfile has changed
  ➜  Local:   http://localhost:4200/
  ➜  press h + enter to show help
Re-optimizing dependencies because lockfile has changed
15:17:17 [vite] Error when evaluating SSR module /@fs/{pathToRepo}/.angular/cache/18.1.0/vite/deps_ssr/@angular_fire_firestore.js?v=de27081b:
|- TypeError: Class extends value undefined is not a constructor or null
    at node_modules/@firebase/auth/node_modules/undici/lib/fetch/file.js (/{pathToRepo}/.angular/cache/18.1.0/vite/deps_ssr/@angular_fire_firestore.js:5662:36)

Please provide a link to a minimal reproduction of the bug

Please provide the exception or error you saw

15:17:17 [vite] Error when evaluating SSR module /@fs/{pathToRepo}/.angular/cache/18.1.0/vite/deps_ssr/@angular_fire_firestore.js?v=de27081b:
|- TypeError: Class extends value undefined is not a constructor or null
    at node_modules/@firebase/auth/node_modules/undici/lib/fetch/file.js (/{pathToRepo}/.angular/cache/18.1.0/vite/deps_ssr/@angular_fire_firestore.js:5662:36)

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 18.1.0
Node: 18.20.2
Package Manager: npm 10.5.0
OS: darwin arm64

Angular: 18.1.0
... animations, build, cdk, cli, common, compiler, compiler-cli
... core, forms, material, platform-browser
... platform-browser-dynamic, platform-server, router, ssr

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1801.0
@angular-devkit/core         18.1.0
@angular-devkit/schematics   18.1.0
@angular/fire                18.0.1
@schematics/angular          18.1.0
rxjs                         7.8.1
typescript                   5.4.5
zone.js                      0.14.7

Anything else?

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 7
  • Comments: 21 (1 by maintainers)

Most upvoted comments

pnpm is a package management system, like yarn or npm itself. Here in the package.json file, "pnpm" is a top-level object used to configure pnpm. undici and undici-types are the only dependencies for which I’m enforcing version resolution. You can read more pnpm’s package_json page.

For yarn you would either use the yarn set resolution command, or you would add the resolutions object to your package.json.

"resolutions": {
 "undici": "6.19.2",
 "undici-types": "6.19.2"
}

For npm, as of version 8.3, you can use the top-level overrides object:

"overrides" : {
  "undici": "6.19.2",
  "undici-types": "6.19.2"
}

reference: https://stackoverflow.com/questions/52416312/npm-equivalent-of-yarn-resolutions

Had the same problem. Looks like the issue is caused by conflicting versions of the undici dependency, installed by @angular/fire and @angular-devkit/build-angular.

pnpm why undici
Legend: production dependency, optional only, dev only

test@0.0.0 ~/workspace/webdocs/test

dependencies:
@angular/fire 18.0.1
├─┬ firebase 10.12.3
│ ├─┬ @firebase/auth 1.7.5
│ │ └── undici 5.28.4
│ ├─┬ @firebase/auth-compat 0.5.10
│ │ ├─┬ @firebase/auth 1.7.5
│ │ │ └── undici 5.28.4
│ │ └── undici 5.28.4
│ ├─┬ @firebase/firestore 4.6.4
│ │ └── undici 5.28.4
│ ├─┬ @firebase/firestore-compat 0.3.33
│ │ └─┬ @firebase/firestore 4.6.4
│ │   └── undici 5.28.4
│ ├─┬ @firebase/functions 0.11.6
│ │ └── undici 5.28.4
│ ├─┬ @firebase/functions-compat 0.3.12
│ │ └─┬ @firebase/functions 0.11.6
│ │   └── undici 5.28.4
│ ├─┬ @firebase/storage 0.12.6
│ │ └── undici 5.28.4
│ └─┬ @firebase/storage-compat 0.3.9
│   └─┬ @firebase/storage 0.12.6
│     └── undici 5.28.4
└─┬ rxfire 6.0.5
  └─┬ firebase 10.12.3 peer
    └─┬ @firebase/auth 1.7.5
      └── undici 5.28.4

devDependencies:
@angular-devkit/build-angular 18.1.0
├─┬ @angular/build 18.1.0
│ └── undici 6.19.2
└── undici 6.19.2

Fix was to simply add an override in package.json (Example for pnpm):

  "pnpm": {
    "overrides" : {
      "undici": "6.19.2",
      "undici-types": "6.19.2"
    }
  }

Then, after deleting the lockfile and node_modules, and reinstalling packages, everything worked.

Hope this helps!

thx @clcarter works.

I hope the angularFire team and implement a proper fix for this but. So far so good. 😃

Closing this since there are no actionable items for us at this time.

The Angular CLI does not depend on undici; it is solely a devDependency and is not installed in the user’s project. The fact that the issue is resolved by the override suggests a problem with undici version 5.28.4, which has been addressed in later versions. Therefore, it is likely that the firebase packages should be updated to use a newer version of undici.