I have a monorepo where my cloud functions import from another package in the workspace. The package that is imported is in the package.json as part of the devDependencies like so:
// stuff
"dependencies": {
"@app/config": "../../packages/config/dist/cjs",
}
// more stuff
When deploying with the CLI using firebase deploy
I end up with the following error message:
Function failed on loading user code. This is likely due to a bug in the user code. Error message: Provided module can't be loaded. Did you list all required modules in the package.json dependencies? Detailed stack trace: Error: Cannot find module '@app/config'
Since I am working in the context of a npm workspace, the dependency in the cloud functions node_modules
is symlinked, not actually installed. So I assume that when the CLI uploads the code and tries to build it in Google Cloud, the link points to a dead end and the build breaks.
After a bit of digging it seems that my two options are:
- publish my package on a (private) registry: github, npm etc.
- add a build step to
npm pack
my dependency and copy it to the cloud functions code base. I assume that this could likely be done with thepredeploy
hook in the firebase.json and a custom script in the repo.
Is there any (simpler) option? And am I on the right track?
Thanks