0x80 / firebase-tools-with-isolate

The Firebase CLI with isolate-package integrated to support monorepos
MIT License
22 stars 0 forks source link

Firebase Hosting can't build Next.Js Cloud Functions for SSR #12

Open KalebKloppe opened 2 weeks ago

KalebKloppe commented 2 weeks ago

Problem

When I deploy a Next.Js app on Firebase Hosting in a pnpm monorepo using firebase-tools-with-isolate

npm error code EUNSUPPORTEDPROTOCOL npm error Unsupported URL Type "workspace:": workspace:*



## Background
 @0x80, you said
 > It looks like your build pipeline is using npm, which doesn't understand the pnpm format.

When Firebase Hosting [deploys Next.Js](https://firebase.google.com/docs/hosting/frameworks/nextjs) I am _assuming_ it uses npm to build the cloud functions that Next.js needs. 

However, I thought that `with-isolate` solved that problem by 'isolating' everything: making a new directory with the workspace pagackes and fixing the links.  So, I would expect npm to be able to find the packages it needs. 

From the error, it looks like the workspace package has not been isolated in the cloud functions step of the build. I'm probably missing something fundamental here.
0x80 commented 2 weeks ago

The workspace: format is something native to PNPM, so NPM doesn't understand it.

Isolate-package will bundle everything so the folder is self-contained to be installed and executed, but it doesn't change the package manager.

I think this problem is really the responsibility of the build pipeline. Is should detect from your manifest and lockfile, that you're using PNPM and use that instead. So it seems Firebase just doesn't support pnpm correctly here.

Isolate-package had an option that forced the output to be NPM format, so you could have used that, but unfortunately I have removed the feature because there wasn't a clear use-case anymore.

I can bring it back probably. I'll have a look. Then at least you have a workaround...

0x80 commented 2 weeks ago

I have published isolate-package@next

I don't have time to publish firebase-tools-with-isolate now, but you should be able to use that package directly. Add a isolate.config.json file with forceNpm: true.

The firebase deployment is a little different that way. Add isolate as a build step in firebase.json and point source to "./isolate" => then deploy with the official firebase-tools

KalebKloppe commented 2 weeks ago

Wow, thank you for throwing that version up so quickly! I will try it with isolate-package@next and forceNpm:true

0x80 commented 2 weeks ago

Good luck, and let me know if it worked out, then I will publish it as the next stable version and update firebase-tools-with-isolate

KalebKloppe commented 2 weeks ago

Hey @0x80,

Unfortunately, I can't tell you if isolate-tools@next works or not. I tried to configure the normal isolate-package back in May, but ended up using firebase-tools-with-isolate at that time. I gave isolate-package a try again yesterday, but still couldn't configure it properly.

We solved our issue by moving from Firebase Hosting to Firebase App Hosting. It works better with Next.js, monorepos, and pnpm. But, we continue to use firebase-tools-with-isolate to deploy our FireCMS admin panel and Cloud Functions.

Switching to Firebase App Hosting has been on our roadmap since it was announced earlier this year. Support for Next.js on regular Hosting was always "experimental", and I doubt Google will continue to support it since App Hosting now exists. Maybe that is part of why they never adopted isolate officially?

It seems like you could direct people to Firebase App Hosting if you wanted to close this issue.