Firebase Functions Monorepo Deployments That Work
Monorepos bring huge advantages for code sharing and consistency, but deploying Firebase Functions from them often leads
to E404 Not Found
errors or TS6059
TypeScript issues. This occurs because Firebase's isolated build environment
doesn't understand local workspace packages or paths
aliases.
After navigating the challenges, a robust solution emerged: packing the shared package into a .tgz
tarball and using
an automated script (predeploy.js
) to manage its inclusion during the deployment process. This guide details this
specific, working workflow based on a real-world setup.
The Core Problem Recapβ
Firebase Functions deployment typically involves:
- Uploading only the specified
functions
directory. - Running
npm install
ornpm ci
based only on thepackage.json
(and potentiallypackage-lock.json
) found within that uploaded directory.
This breaks when npm
tries to find local workspace packages (like @your-org/common
) because they aren't on the
public registry and the rest of the workspace isn't present. TypeScript paths
pointing to local source can also cause
TS6059
(rootDir) errors during builds.
The Solution: Automated .tgz
Packingβ
This method ensures the shared package is treated like a regular dependency within the deployment package itself: