Deploying monorepo w/ react front-end & firebase functions backend. Can it be done?

Hey all!

The project we’re working with is a monorepo w/ 2 package.json files. JS front-end (react/CRA), Firebase cloud functions back-end. Not currently using a custom domain.

Project Hierarchy:

/ project-root
|
| # Front-end
|- package.json
|- package-lock.json
|- src/
|- src/core
|- src/pages
|- src/components
|- src/shared
|- src/**/(misc others)
|
| # Back-end
|- functions/package.json
|- functions/package-lock.json
|- functions/node_modules/**/...
|- functions/handlers
|- functions/models
|- functions/**/(misc others)

Here’s the main obstacles I see:
I. Two package.json means two builds.
Netlify docs recommend merging package.json files. If possible, I’d like to avoid this option. The project is an inheritted codebase, it’s poorly designed & needs a lot of clean up. I’m interested in keeping the back/front seperate to the best of my ability (until the codebases are more stable). Is there a way to define two seperate builds in netlify.toml?

II. Two build means two dynamic netlify endpoints (AFAIK)
The front-end uses env vars for api endpoints. Would it be possible to build/deploy the firebase functions, capture the dynamic endpoint & overwrite a build env var so the front-end can send requests to the netlify deployed back-end?

Netlify Site ID: aesthetic-lollipop-002cff
Netlify Deploy Log:

6:04:53 PM: Build ready to start
6:04:55 PM: build-image version: d7b3813f01c06610bc1723ff1b22446513ee7941 (focal)
6:04:55 PM: build-image tag: v4.14.3
6:04:55 PM: buildbot version: 0a9525e006898c513bdd79a097f61c04604a28eb
6:04:55 PM: Fetching cached dependencies
6:04:55 PM: Failed to fetch cache, continuing with build
6:04:55 PM: Starting to prepare the repo for build
6:04:55 PM: No cached dependencies found. Cloning fresh repo
6:04:55 PM: git clone https://github.com/usabg-llc/usabg-backoffice-ui
6:04:58 PM: Preparing Git Reference refs/heads/dev/UAD-1183
6:04:59 PM: Parsing package.json dependencies
6:05:00 PM: Section completed: initializing
6:05:00 PM: Starting build script
6:05:00 PM: Installing dependencies
6:05:00 PM: Python version set to 2.7
6:05:00 PM: Downloading and installing node v16.18.1...
6:05:00 PM: Downloading https://nodejs.org/dist/v16.18.1/node-v16.18.1-linux-x64.tar.xz...
6:05:01 PM: Computing checksum with sha256sum
6:05:01 PM: Checksums matched!
6:05:02 PM: Now using node v16.18.1 (npm v8.19.2)
6:05:03 PM: Enabling node corepack
6:05:03 PM: Started restoring cached build plugins
6:05:03 PM: Finished restoring cached build plugins
6:05:03 PM: Attempting ruby version 2.7.2, read from environment
6:05:03 PM: Using ruby version 2.7.2
6:05:03 PM: Using PHP version 8.0
6:05:04 PM: No npm workspaces detected
6:05:04 PM: Started restoring cached node modules
6:05:04 PM: Finished restoring cached node modules
6:05:04 PM: Installing NPM modules using NPM version 8.19.2
6:05:05 PM: npm WARN old lockfile
6:05:05 PM: npm WARN old lockfile The package-lock.json file was created with an old version of npm,
6:05:05 PM: npm WARN old lockfile so supplemental metadata must be fetched from the registry.
6:05:05 PM: npm WARN old lockfile
6:05:05 PM: npm WARN old lockfile This is a one-time fix-up, please be patient...
6:05:05 PM: npm WARN old lockfile
6:05:17 PM: npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
6:05:18 PM: npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
6:05:18 PM: npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
6:05:18 PM: npm WARN deprecated w3c-hr-time@1.0.2: Use your platform's native performance.now() and performance.timeOrigin.npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
6:05:19 PM: npm WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
6:05:19 PM: npm WARN deprecated sane@4.1.0: some dependency vulnerabilities fixed, support for node < 10 dropped, and newer ECMAScript syntax/features added
6:05:19 PM: npm WARN deprecated request-promise-native@1.0.9: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142
6:05:20 PM: npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
6:05:20 PM: npm WARN deprecated plugin-log@0.1.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
6:05:21 PM: npm WARN deprecated left-pad@1.3.0: use String.prototype.padStart()
6:05:22 PM: npm WARN deprecated har-validator@5.1.5: this library is no longer supported
6:05:22 PM: npm WARN deprecated flatten@1.0.3: flatten is deprecated in favor of utility frameworks such as lodash.
6:05:22 PM: npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
6:05:22 PM: npm WARN deprecated html-webpack-plugin@4.0.0-beta.11: please switch to a stable version
6:05:23 PM: npm WARN deprecated eslint-loader@3.0.3: This loader has been deprecated. Please use eslint-webpack-plugin
6:05:24 PM: npm WARN deprecated babel-eslint@10.0.3: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
6:05:24 PM: npm WARN deprecated @types/date-fns@2.6.0: This is a stub types definition for date-fns (https://github.com/date-fns/date-fns). date-fns provides its own type definitions, so you don't need @types/date-fns installed!
6:05:25 PM: npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
6:05:25 PM: npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
6:05:25 PM: npm WARN deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address'
6:05:25 PM: npm WARN deprecated popper.js@1.16.1: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1
6:05:25 PM: npm WARN deprecated @material-ui/system@3.0.0-alpha.2: You can now upgrade to @mui/system. See the guide: https://mui.com/guides/migration-v4/
6:05:25 PM: npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
6:05:25 PM: npm WARN deprecated material-ui-pickers@2.2.4: You can now upgrade to @material-ui/pickers. Documentation for v2 can be found at https://material-ui-pickers-v2.dmtr-kovalenko.now.sh/
6:05:25 PM: npm WARN deprecated @hapi/joi@15.1.1: Switch to 'npm install joi'
6:05:26 PM: npm WARN deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
6:05:26 PM: npm WARN deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
6:05:28 PM: npm WARN deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
6:05:28 PM: npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
6:05:28 PM: npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
6:05:31 PM: npm WARN deprecated core-js@1.2.7: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
6:05:31 PM: npm WARN deprecated @material-ui/core@3.9.3: You can now upgrade to @mui/material. See the guide: https://mui.com/guides/migration-v4/
6:05:31 PM: npm WARN deprecated core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
6:05:31 PM: npm WARN deprecated core-js@3.6.5: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
6:05:39 PM: added 2228 packages, and audited 2229 packages in 35s
6:05:39 PM: 135 packages are looking for funding
6:05:39 PM:   run `npm fund` for details
6:05:40 PM: 71 vulnerabilities (3 low, 18 moderate, 43 high, 7 critical)
6:05:40 PM: To address issues that do not require attention, run:
6:05:40 PM:   npm audit fix
6:05:40 PM: To address all issues (including breaking changes), run:
6:05:40 PM:   npm audit fix --force
6:05:40 PM: Run `npm audit` for details.
6:05:40 PM: NPM modules installed
6:05:40 PM: Creating package sha
6:05:40 PM: Started restoring cached go cache
6:05:40 PM: Finished restoring cached go cache
6:05:40 PM: Installing Go version 1.17 (requested 1.17)
6:05:44 PM: unset GOOS;
6:05:44 PM: unset GOARCH;
6:05:44 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.17.linux.amd64';
6:05:44 PM: export PATH="/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}";
6:05:44 PM: go version >&2;
6:05:44 PM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.17.linux.amd64.env"
6:05:44 PM: go version go1.17 linux/amd64
6:05:44 PM: Detected 2 framework(s)
6:05:44 PM: "create-react-app" at version "3.4.0"
6:05:44 PM: "gulp" at version "4.0.2"
6:05:44 PM: Installing missing commands
6:05:44 PM: Verify run directory
6:05:46 PM: ​
6:05:46 PM: ────────────────────────────────────────────────────────────────
6:05:46 PM:   Netlify Build                                                 
6:05:46 PM: ────────────────────────────────────────────────────────────────
6:05:46 PM: ​
6:05:46 PM: ❯ Version
6:05:46 PM:   @netlify/build 28.1.13
6:05:46 PM: ​
6:05:46 PM: ❯ Flags
6:05:46 PM:   baseRelDir: true
6:05:46 PM:   buildId: 6372c9956f226e0009cab5ce
6:05:46 PM:   deployId: 6372c9956f226e0009cab5d0
6:05:46 PM: ​
6:05:46 PM: ❯ Current directory
6:05:46 PM:   /opt/build/repo
6:05:46 PM: ​
6:05:46 PM: ❯ Config file
6:05:46 PM:   /opt/build/repo/netlify.toml
6:05:46 PM: ​
6:05:46 PM: ❯ Context
6:05:46 PM:   branch-deploy
6:05:46 PM: ​
6:05:46 PM: ────────────────────────────────────────────────────────────────
6:05:46 PM:   1. Build command from Netlify app                             
6:05:46 PM: ────────────────────────────────────────────────────────────────
6:05:46 PM: ​
6:05:46 PM: $ npm run build
6:05:46 PM: > usabg-agent-dashboard@1.4.57 prebuild
6:05:46 PM: > npm run generate-build-version
6:05:46 PM: > usabg-agent-dashboard@1.4.57 generate-build-version
6:05:46 PM: > node generate-build-version
6:05:46 PM: meta.json file has been saved with latest version number
6:05:46 PM: > usabg-agent-dashboard@1.4.57 build
6:05:46 PM: > react-app-rewired build
6:05:47 PM: Creating an optimized production build...
6:06:10 PM: The prop value with an expression type of PrivateName could not be resolved. Please file issue to get this fixed immediately.
6:06:10 PM: The prop value with an expression type of PrivateName could not be resolved. Please file issue to get this fixed immediately.
6:06:10 PM: The prop value with an expression type of PrivateName could not be resolved. Please file issue to get this fixed immediately.
6:06:10 PM: The prop value with an expression type of PrivateName could not be resolved. Please file issue to get this fixed immediately.
6:06:10 PM: The prop value with an expression type of PrivateName could not be resolved. Please file issue to get this fixed immediately.
6:06:15 PM: The prop value with an expression type of PrivateName could not be resolved. Please file issue to get this fixed immediately.
6:06:15 PM: The prop value with an expression type of PrivateName could not be resolved. Please file issue to get this fixed immediately.
6:06:19 PM: The prop value with an expression type of PrivateName could not be resolved. Please file issue to get this fixed immediately.
6:06:20 PM: The prop value with an expression type of PrivateName could not be resolved. Please file issue to get this fixed immediately.
6:06:24 PM: The prop value with an expression type of PrivateName could not be resolved. Please file issue to get this fixed immediately.
6:06:24 PM: The prop value with an expression type of PrivateName could not be resolved. Please file issue to get this fixed immediately.
6:06:25 PM: The prop value with an expression type of PrivateName could not be resolved. Please file issue to get this fixed immediately.
6:06:25 PM: The prop value with an expression type of PrivateName could not be resolved. Please file issue to get this fixed immediately.
6:06:46 PM: The prop value with an expression type of PrivateName could not be resolved. Please file issue to get this fixed immediately.
6:06:47 PM: The prop value with an expression type of PrivateName could not be resolved. Please file issue to get this fixed immediately.
6:06:47 PM: The prop value with an expression type of PrivateName could not be resolved. Please file issue to get this fixed immediately.
6:06:47 PM: The prop value with an expression type of PrivateName could not be resolved. Please file issue to get this fixed immediately.
6:06:47 PM: The prop value with an expression type of PrivateName could not be resolved. Please file issue to get this fixed immediately.
6:06:47 PM: The prop value with an expression type of PrivateName could not be resolved. Please file issue to get this fixed immediately.
6:06:47 PM: The prop value with an expression type of PrivateName could not be resolved. Please file issue to get this fixed immediately.
6:06:47 PM: The prop value with an expression type of PrivateName could not be resolved. Please file issue to get this fixed immediately.
6:06:56 PM: The prop value with an expression type of PrivateName could not be resolved. Please file issue to get this fixed immediately.
6:08:16 PM: Compiled successfully.
6:08:16 PM: 
6:08:16 PM: File sizes after gzip:
6:08:17 PM:   940.72 KB  build/static/js/6.bc4761a2.chunk.js
6:08:17 PM:   862.12 KB  build/static/js/3.2feead02.chunk.js
6:08:17 PM:   487.68 KB  build/static/js/main.131c7eec.chunk.js
6:08:17 PM:   271.2 KB   build/static/css/main.ceef3f0c.chunk.css
6:08:17 PM:   159.16 KB  build/static/js/5.3ad5d786.chunk.js
6:08:17 PM:   55.95 KB   build/static/js/4.1f0bc564.chunk.js
6:08:17 PM:   50.65 KB   build/static/css/3.a1799d20.chunk.css
6:08:17 PM:   1.22 KB    build/static/js/runtime-main.c3cfb308.js
6:08:17 PM:   152 B      build/static/js/xlsx.e1e87355.chunk.js
6:08:17 PM: The project was built assuming it is hosted at /.
6:08:17 PM: You can control this with the homepage field in your package.json.
6:08:17 PM: The build folder is ready to be deployed.
6:08:17 PM: You may serve it with a static server:
6:08:17 PM:   npm install -g serve
6:08:17 PM:   serve -s build
6:08:17 PM: Find out more about deployment here:
6:08:17 PM:   bit.ly/CRA-deploy
6:08:17 PM: ​
6:08:17 PM: (build.command completed in 2m 31.2s)
6:08:17 PM: ​
6:08:17 PM: ────────────────────────────────────────────────────────────────
6:08:17 PM:   2. Functions bundling                                         
6:08:17 PM: ────────────────────────────────────────────────────────────────
6:08:17 PM: ​
6:08:17 PM: Packaging Functions from functions directory:
6:08:17 PM:  - index.js
6:08:17 PM: ​
6:08:18 PM: ​
6:08:18 PM: ────────────────────────────────────────────────────────────────
6:08:18 PM:   Dependencies installation error                               
6:08:18 PM: ────────────────────────────────────────────────────────────────
6:08:18 PM: ​
6:08:18 PM:   Error message
6:08:18 PM:   A Netlify Function is using "busboy" but that dependency has not been installed yet.
6:08:18 PM: ​
6:08:18 PM:   By default, dependencies inside a Netlify Function's "package.json" are not automatically installed.  There are several ways to fix this problem:
6:08:18 PM:     - Removing your Function's "package.json" and adding the dependencies to the project's top-level "package.json" instead. This is the fastest and safest solution.
6:08:18 PM:     - Running "npm install" or "yarn" inside your Netlify Function in your build command.
6:08:18 PM:     - Adding the following plugin to your "netlify.toml":
6:08:18 PM: ​
6:08:18 PM:   [[plugins]]
6:08:18 PM:   package = "@netlify/plugin-functions-install-core"
6:08:18 PM: ​​
6:08:18 PM:   In file "/opt/build/repo/functions/index.js"
6:08:18 PM:   Cannot find module 'busboy'
6:08:18 PM:   Require stack:
6:08:18 PM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/bundlers/zisi/resolve.js
6:08:18 PM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/bundlers/zisi/traverse.js
6:08:18 PM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/bundlers/esbuild/src_files.js
6:08:18 PM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/bundlers/esbuild/index.js
6:08:18 PM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/bundlers/index.js
6:08:18 PM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/index.js
6:08:18 PM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/index.js
6:08:18 PM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/main.js
6:08:18 PM: ​
6:08:18 PM:   Resolved config
6:08:18 PM:   build:
6:08:18 PM:     command: npm run build
6:08:18 PM:     commandOrigin: ui
6:08:18 PM:     environment:
6:08:18 PM:       - REACT_APP_ADOBE_SIGN_CLIENT_ID
6:08:18 PM:       - REACT_APP_API_BASEURL
6:08:18 PM:       - REACT_APP_FIREABSE_API_KEY
6:08:18 PM:       - REACT_APP_FIREABSE_AUTH_DOMAIN
6:08:18 PM:       - REACT_APP_FIREABSE_MESSAGING_SENDER_ID
6:08:18 PM:       - REACT_APP_FIREABSE_PROJECT_ID
6:08:18 PM:       - REACT_APP_FIREABSE_STORAGE_BUCKET
6:08:18 PM:       - REACT_APP_STORAGE_ENCODE_KEYS
6:08:18 PM:       - REACT_APP_STRIPE_KEY
6:08:18 PM:       - REACT_APP_STRIPE_SECRET
6:08:18 PM:       - REACT_APP_TRACKJS_APP
6:08:18 PM:       - REACT_APP_TRACKJS_DISPLAY_CONSOLE
6:08:18 PM:       - REACT_APP_TRACKJS_KEY
6:08:20 PM: Creating deploy upload records
6:08:18 PM:       - REACT_APP_VERSION
6:08:18 PM:     publish: /opt/build/repo/build
6:08:18 PM:     publishOrigin: ui
6:08:18 PM:   functionsDirectory: /opt/build/repo/functions
6:08:19 PM: Caching artifacts
6:08:21 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
6:08:19 PM: Started saving node modules
6:08:19 PM: Finished saving node modules
6:08:19 PM: Started saving build plugins
6:08:19 PM: Finished saving build plugins
6:08:19 PM: Started saving pip cache
6:08:19 PM: Finished saving pip cache
6:08:19 PM: Started saving emacs cask dependencies
6:08:19 PM: Finished saving emacs cask dependencies
6:08:19 PM: Started saving maven dependencies
6:08:19 PM: Finished saving maven dependencies
6:08:19 PM: Started saving boot dependencies
6:08:19 PM: Finished saving boot dependencies
6:08:19 PM: Started saving rust rustup cache
6:08:19 PM: Finished saving rust rustup cache
6:08:19 PM: Started saving go dependencies
6:08:19 PM: Finished saving go dependencies
6:08:20 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
6:08:21 PM: Failing build: Failed to build site
6:08:21 PM: Finished processing build request in 3m25.905702987s

One thing I’m confused about. If you have got Firebase functions, how do you expect them to work on Netlify? Shouldn’t they be deployed to Firebase?