-
Notifications
You must be signed in to change notification settings - Fork 944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support mono-repos in deployment #653
Comments
This seems to work in my setup, i.e. EDIT: Moreover, I copy
So, 2 levels of nesting still resolve the root |
@dinvlad could you share a repo? |
@orouz unfortunately not yet, it's closed source for now. |
Does anyone managed to tackle this problem? Sharing simple example project would be very useful. |
@audkar Currently I just use lerna.js.org and it's
Ensuring the discussed here previously - #1116 |
@jthegedus thank you for your reply. But I think issue of this ticket is different. I am trying to use yarn workspaces. And seems that firebase tools doesn't pickup symlink dependencies when uploading functions |
Ah fair enough, I've avoided that rabbit hole myself |
Could you elaborate what the issue is? As mentioned above, I just use bare Yarn with
Then I just run "functions": {
"source": "api/dist"
},
"hosting": {
"public": "app/dist", Unfortunately, I still can’t share the full code, but this setup is all that matters, afaik. |
Also, I might be wrong but I think the |
That's true. The default value of "functions.ignore" in firebase.json is
["node_modules"] so it's not uploaded. I believe you can override that
though if you want to ship up some local modules.
…On Mon, Jun 17, 2019, 6:58 PM Denis Loginov ***@***.***> wrote:
Also, I might be wrong but I think the firebase deploy script doesn’t
actually use your node_modules directory. I think it just picks up the
cod, package.json, and yarn.lock from the dist directories, and does the
rest.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#653?email_source=notifications&email_token=ACATB2U73VS2KIILUVRFFB3P3A6NPA5CNFSM4EOR24GKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODX46ABQ#issuecomment-502915078>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACATB2U3Q2TLVBICRJ3B5OLP3A6NPANCNFSM4EOR24GA>
.
|
@dinvlad Yes, it requires the I believe the scenario originally outlined in the other issue was using a shared package within the workspace and some issues with scope-hoisting. As I was not using yarn this way I can only speculate from what I have read there. |
@samtstern @jthegedus thanks, good to know! |
Seems we all talk about different problems. I will try to describe Problematic projectproject layout
./package.json
functions/package.json
ProblemError during function deployment:
Functions works fine locally on emulator. Solutions triedUploading My guess that it is because Could it be that firebase-tools doesn't include content of symlink'ed modules when uploading (no dereferencing)? |
Sorry, could you clarify which folder your |
firebase.json was in root folder. Configuration was standard. Smth like this:
everything was deployed as expected (including node_modules) except I manage to workaround this issue by writing few scripts which:
output dir content before upload:
|
@audkar Today I ran into the same issue as you. I am new to both Lerna and Yarn workspaces. As I understand it you can also just use Lerna. Would that help in any way? Your workaround seems a bit complicated for me 🤔 Also wondering, what is `--cwd "$RESOURCE_DIR" for? |
|
@audkar Ah I see. So you could do the same with |
@dinvlad It is unclear to me why you are targeting the dist folder and copying things over there. If you build to dist, but leave the package.json where it is and point main to |
@0x80 I copy Re |
@dinvlad it will bundle the root of what you point it to, but you can put everything that you don't want included in the firebase.json ignore list. I've now used a similar workaround to @audkar. {
"functions": {
"source": "packages/cloud-functions",
"predeploy": ["./scripts/pre-deploy-cloud-functions"],
"ignore": [
"src",
"node_modules"
]
}
} Then the pre-deploy-cloud-functions script is: #!/usr/bin/env bash
set -e
yarn workspace @gemini/common lint
yarn workspace @gemini/common build
cd packages/common
yarn pack --filename gemini-common.tgz
mv gemini-common.tgz ../cloud-functions/
cd -
cp yarn.lock packages/cloud-functions/
yarn workspace @gemini/cloud-functions lint
yarn workspace @gemini/cloud-functions build
And packages/cloud-functions has an extra gitignore file:
|
here's what worked for me
and in the
|
@kaminskypavel is your packages/functions depending on packages/package1 (or some other sibling package)? |
@0x80 positive. |
I think there was something fundamental I misunderstood about monorepos. I assumed you can share a package and deploy an app using that package without actually publishing the shared package to NPM. It seems that this is not possible, because deployments like Firebase or Now.sh will usually upload the code and then in the cloud do an install and build. Am I correct? @kaminskypavel I tried your approach and it works, but only after publishing my package to NPM first. Because in my case the package is private I initially got a "not found" error, so I also had to add my .npmrc file to the root of the cloud functions package as described here @audkar Are you publishing your common package to NPM, or are you like me trying to deploy with shared code which is not published? |
@0x80 I'm with you on this understanding - I think Firebase Function deployments are just (erroneously) assuming that all packages named in package.json will be available on npm, in the name of speeding up deployments. As yarn workspace setups are becoming more popular, I imagine more folks are going to be surprised that they can't use symlinked packages in Firebase Functions – especially since they work fine until you deploy. |
Thanks bro! @0x80 the isolate-package works like a charm for me. |
Solution: Similar to this solutions: #653 (comment) from @johanneskares I believe it is quite elegant and it works fine. Just create a postdeploy.js and predeploy.js file and modify firebase.json Npm workspaces are used in the project (but will work with any workspace). File structure
file: /firebase.json
file: /functions/predeploy.js
file: /functions/postdeploy.js
|
+1. Would be awesome to support turborepo + pnpm |
I have been busy lately trying to overcome the last major hurdles and I have some exciting news to share!
I hope to publish an article about it later this week, but the monorepo readme and code should already contain all the information you need. The main thing left to do is to also generate lockfiles for NPM and Yarn. For NPM there is arborist, and for Yarn I think there is some user-land code... I tried arborist briefly but NPM was giving me issues, and my focus was on PNPM because it is my preferred package manager. I plan to give arborist another try later this week. The integration with the firebase-tools could be improved, and I would love for the Firebase team to help me out on this, because it seems that some refactoring is needed to get all the log messages to display 100% correct information. But I think this works fine for now and because I don't expect it to be part of firebase-tools any time soon, I made the fork available on NPM. Enjoy! 🌈 |
@BartSpangenberg have you seen this error? I tried to use your setup in monorepo (pnpm + turbo).
However, in api/package.json i saw that script changed a reference from |
🔥 I have now added support for NPM lockfiles in It turned out to be much easier than figuring this out for PNPM. It's also much slower than PNPM though, but that's maybe not surprising. The latter is released as a pre-release number because I did not want to mess up the version match with the original firebase-tools. When 12.9.2 comes out I will likely release an updated version 12.9.2 of firebase-tools-with-isolate, and so on, to keep it in sync. It would obviously be nice to also support Yarn lockfiles, but honestly, for me, it's not a priority at all, so I might wait for someone to show me how to do it or make a PR. Have fun! |
NPM lockfiles are deploying again with |
Some updates:
firebase-tools-with-isolate has been synced with upstream firebase-tools to match to latest version 13.0.2 The mono-ts boilerplate, showcasing both, now has two alternative branches, one for NPM and one for Yarn classic. I haven't figured out how to generate lockfiles for modern Yarn versions yet, but as a fallback it could just generate an NPM lockfile if you use a package manager that is not supported. I don't think it matters what package manager is used in your cloud deployment, as long as the isolated lockfile versions match your original lockfile. |
🔥 More happy news from version 1.9.x
The mono-ts boilerplate now contains 4 parallel branches:
Enjoy! |
I bumped into this thread after long research because I am unable to deploy a nextJs app using Nx monorepo. Might be my bad for not searching priorly the tools properly, but supporting a monorepo nowadays should be a must for such a big service that is firebase. I was planning to go full firebase/firestore/firebase-auth but I am stuck at this step that I thought would be the easiest ^^' |
Are there any updates here? My product owner/client is slowly forcing me to host elsewhere... but I don't want to. ^^" |
@SvenBudak Sounds dramatic :) Are the known workarounds and solutions not sufficient for your client? The isolate-package approach seems to be solid. Some people have also been using it for other types of deployments like google cloud functions (outside of firebase) and cloud run. The only caveat is that using NPM is problematic if you want to deploy with pruned lockfiles to multiple platforms in parallel, because the lockfile pruning (based on npmcli Arborist) currently can not execute in parallel To get around it you could deploy in series, use PNPM or Yarn instead of NPM, or omit the lockfile (not recommended) |
Has anyone tried the Turborepo prune command for Firebase deployments? It seems very similar to what isolate-package is doing. Also, Nx has an option to generate a pruned lockfile. I remember looking at Nx and somehow concluding that it was not what I wanted, but I can't recall why. So I'm also curious to hear if anyone tried that. |
Hi all, Just a small update to tell you I have released isolate-package@1.13.0 and firebase-tools-with-isolate@13.6.2 and this includes support for Rush monorepos. It has only been tested with PNPM but I am fairly confident that NPM and Yarn will work too. Notable recent changes:
|
Hi @0x80 I just gave firebase-tools-with-isolate a go and I'm impressed.
Thanks for you efforts on this! |
Hey everyone, I'm encountering an issue while using a monorepo with Bun. When I run my setup, I receive the following error:
Our setup includes TypeScript and Has anyone faced a similar issue or have any suggestions on how to resolve this? Thanks in advance! |
@e-CORS I don't think it has to do with your code. It's probably the cloud build complaining about the workspace paths in your package.json file. PNPM also uses these but the build pipeline will switch to using PNPM as the package manager when it is detected. In your case you are using Bun as the package manager which I don't think would be supported by a cloud infrastructure that is based on Node.js. That said, I have no experience with Bun, so I don't know what your options are. |
Hey @0x80 by running |
When I deploy a Next.Js app in my pnpm monorepo using
|
@KalebKloppe This is not the place to report issues for that package, please do that in its own repo. It looks like your build pipeline is using npm, which doesn't understand the pnpm format. |
There are some calls to npm harcoded into the firebase-tools repo, so I don't think this is necessarily about @KalebKloppe's build pipeline. I think the line I linked is one of the things @KalebKloppe is running into. I say this specifically because it tripped me up, too: Firebase Functions advertise some compatibility with pnpm, and yet Firebase Tools attempts to use npm when deploying the Next.js backend function. |
@staticshock Indeed, that was also my conclusion. Firebase-tools is not detecting the used package manager. In that sense @KalebKloppe was reporting in the right repo after all, just not the right issue :) isolate-package had a setting to force its output to use npm, but unfortunately I had removed the feature since there was no clear use-case, and it complicated the code. I've now restored the feature and published it under isolate-package@next. It'll make it into firebase-tools-with-isolate once I get the confirmation that it works. |
See: firebase/firebase-functions#172
Version info
3.17.3
Steps to reproduce
Expected behavior
Actual behavior
The text was updated successfully, but these errors were encountered: