Environment
- Nitro (nitropack): 2.13.4
- Node.js: 22.16.0 / 24.16.0
- Nuxt: 4.4.7
- Package manager: pnpm 11.5.2
- nitro config:
nitro: { preset: 'firebase', firebase: { gen: 2, nodeVersion: '22' } }
Reproduction
A minimal reproduction repo can be provided on request, but the broken artifact is observable from any firebase (gen2) preset build:
- Nuxt/Nitro app with
nitro: { preset: 'firebase', firebase: { gen: 2, nodeVersion: '22' } }.
nuxt build (or nitro build).
- Inspect the output:
cat .output/server/node_modules/firebase-functions/package.json # has an "exports" map
ls .output/server/node_modules/firebase-functions/lib # empty — referenced files are absent
node -e "require.resolve('firebase-functions', { paths: ['.output/server'] })" # throws ERR_MODULE_NOT_FOUND
- Deploy with current
firebase-tools (v15): firebase deploy --only functions --debug → aborts.
Describe the bug
The firebase preset writes .output/server/node_modules/firebase-functions/ as a stub consisting of only a package.json (plus an empty lib/ directory). The actual SDK code is bundled into server.mjs, but the stub package.json still carries an exports map copied from the real package:
{
"exports": {
".": {
"types": "./lib/v2/index.d.ts",
"import": "./lib/esm/v2/index.mjs",
"require": "./lib/v2/index.js"
}
}
}
None of those files are emitted, so the package is unresolvable: any consumer that does require.resolve('firebase-functions', { paths: [outputServerDir] }) follows the exports require/import condition to a missing file and throws ERR_MODULE_NOT_FOUND. In effect the preset emits a package whose exports advertise entry points it does not ship.
This now breaks deployment. firebase-tools v15 added a require.resolve('firebase-functions', { paths: [sourceDir] }) call in its node runtime delegate (findFunctionsBinary), so firebase deploy of a Nitro-built functions codebase crashes with An unexpected error has occurred.. It worked on firebase-tools v14, which did not resolve the SDK from the source dir.
I'll also raise the lack of try/catch on the firebase-tools side separately, but Nitro is producing a technically-invalid package (an exports map pointing to files it doesn't ship), which is the trigger.
Suggested directions (any one resolves it):
- Don't write a
node_modules/firebase-functions stub at all (the code is already bundled into server.mjs and isn't needed at runtime), or
- Write the stub
package.json without the exports field (so resolution falls back instead of advertising missing subpaths), or
- Actually emit the files referenced by
exports.
Happy to help with a PR once the preferred direction is decided.
Logs
i functions: Loading and analyzing source code for codebase lp to determine what to deploy
Could not parse firebase-functions version '' into semver.
Could not find functions.yaml. Must use http discovery
Error: Cannot find module '<project>/.output/server/node_modules/firebase-functions/lib/v2/index.js'
at createEsmNotFoundErr (node:internal/modules/cjs/loader:1437:15)
at finalizeEsmResolution (node:internal/modules/cjs/loader:1426:15)
at resolveExports (node:internal/modules/cjs/loader:657:14)
at Function._findPath (node:internal/modules/cjs/loader:749:31)
at Function._resolveFilename (node:internal/modules/cjs/loader:1387:27)
at Function.resolve (node:internal/modules/helpers:145:19)
at Delegate.findFunctionsBinary (firebase-tools/lib/deploy/functions/runtimes/node/index.js:101:33)
at Delegate.spawnFunctionsProcess (firebase-tools/lib/deploy/functions/runtimes/node/index.js:131:30)
at Delegate.serveAdmin (firebase-tools/lib/deploy/functions/runtimes/node/index.js:152:35)
at Delegate.discoverBuild (firebase-tools/lib/deploy/functions/runtimes/node/index.js:192:41)
Environment
Reproduction
A minimal reproduction repo can be provided on request, but the broken artifact is observable from any
firebase(gen2) preset build:nitro: { preset: 'firebase', firebase: { gen: 2, nodeVersion: '22' } }.nuxt build(ornitro build).firebase-tools(v15):firebase deploy --only functions --debug→ aborts.Describe the bug
The
firebasepreset writes.output/server/node_modules/firebase-functions/as a stub consisting of only apackage.json(plus an emptylib/directory). The actual SDK code is bundled intoserver.mjs, but the stubpackage.jsonstill carries anexportsmap copied from the real package:{ "exports": { ".": { "types": "./lib/v2/index.d.ts", "import": "./lib/esm/v2/index.mjs", "require": "./lib/v2/index.js" } } }None of those files are emitted, so the package is unresolvable: any consumer that does
require.resolve('firebase-functions', { paths: [outputServerDir] })follows theexportsrequire/importcondition to a missing file and throwsERR_MODULE_NOT_FOUND. In effect the preset emits a package whoseexportsadvertise entry points it does not ship.This now breaks deployment.
firebase-toolsv15 added arequire.resolve('firebase-functions', { paths: [sourceDir] })call in its node runtime delegate (findFunctionsBinary), sofirebase deployof a Nitro-built functions codebase crashes withAn unexpected error has occurred.. It worked onfirebase-toolsv14, which did not resolve the SDK from the source dir.I'll also raise the lack of try/catch on the firebase-tools side separately, but Nitro is producing a technically-invalid package (an
exportsmap pointing to files it doesn't ship), which is the trigger.Suggested directions (any one resolves it):
node_modules/firebase-functionsstub at all (the code is already bundled intoserver.mjsand isn't needed at runtime), orpackage.jsonwithout theexportsfield (so resolution falls back instead of advertising missing subpaths), orexports.Happy to help with a PR once the preferred direction is decided.
Logs