Repository navigation
Description
[REQUIRED] Environment info
firebase-tools: 11.22.0
Platform: Windows
[REQUIRED] Test case
npx firebase deploy
[REQUIRED] Steps to reproduce
The error occurs when using a nuxt v3.1.1 app in a monorepo.
First I build the app for production with npx cross-env NITRO_PRESET=firebase npm run build
Then I deploy on Firebase Hosting with npx firebase deploy
Here is my firebase.json :
{
"functions": [
{
"source": ".output/server",
"codebase": "nuxt"
},
{
"source": "functions",
"codebase": "functions",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
],
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
}
],
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"hosting": {
"public": ".output/public",
"cleanUrls": true,
"rewrites": [{ "source": "**", "function": "server" }],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
[REQUIRED] Expected behavior
Before upgrading to firebase-tools 11.22.0, I used 11.21.0 version. I was able to deploy on Firebase Hosting (although I was facing the #4952 issue and used the fix mentionned in the thread).
[REQUIRED] Actual behavior
I get following error :
Error: Failed to find location of Firebase Functions SDK. Please file a bug on Github (https://github.com/firebase/firebase-tools/).
The content of firebase-debug.log :
[debug] [2023-02-01T22:01:08.076Z] ----------------------------------------------------------------------
[debug] [2023-02-01T22:01:08.082Z] Command: C:\Program Files\nodejs\node.exe C:\Users\plsch\AppData\Roaming\npm\node_modules\firebase-tools\lib\bin\firebase.js deploy --debug flag
[debug] [2023-02-01T22:01:08.084Z] CLI Version: 11.22.0
[debug] [2023-02-01T22:01:08.084Z] Platform: win32
[debug] [2023-02-01T22:01:08.084Z] Node Version: v16.16.0
[debug] [2023-02-01T22:01:08.086Z] Time: Wed Feb 01 2023 23:01:08 GMT+0100 (heure normale d’Europe centrale)
[debug] [2023-02-01T22:01:08.087Z] ----------------------------------------------------------------------
[debug]
[error]
[error] Error: Too many arguments. Run firebase help deploy for usage instructions
Activity
memic84 commentedon Feb 4, 2023
Same here.
My config
And after running firebase deploy --debug
This is also a Nuxt 3 setup, with present Firebase.
DevJoghurt commentedon Feb 6, 2023
This bug is a tracing error in unjs/nitro. It may be possible to fix this with a different packaging strategy on the firebase side but I don't know about that. I have already made a fix for nuxt:
nitrojs/nitro#627
In addition, you can now also use the following firebase config:
{ "functions": [{ "source": "./functions", "runtime": "nodejs18", "codebase": "fbFunctions" }], "hosting": [ { "site": "nuxt-app", "source": "./app", "cleanUrls": true, "rewrites": [ { "source": "/any-function", "function": "testfunction" } ] } ] }If you specify the nuxt app folder under "source", then firebase builds the app and that works fine for me.
rensvis commentedon Feb 8, 2023
I'm having the same problem. Also Nuxt 3.
DevJoghurt commentedon Feb 9, 2023
@rensvis Sorry, I may have been unclear.
Currently there are two tooling strategies to get a Nuxt 3 app on firebase and both don't work properly:
.output/serverfolder and donpm install. Then you can usefirebase deployto publish the app. This solution is of course contrary to tracing by nitro and increases the package load. My fix for nitro would solve this problem though.Your firebase.json would look like this with this tooling strategy:
{ "hosting": { "site": "rens-vis-nuxt", "ignore": ["firebase.json", "**/.*", "**/node_modules/**"], "cleanUrls": true } }A function for nuxt would no longer need to be entered, as this would be handled by firebase cli. In my example I have only given another function folder as an example for further firebase functions.
You can now simply use the firebase cli for building the app:
However, I still ran into a few problems that I'm trying to solve in my pull request.
I hope this helps to understand a little better what the current state of nuxt3 and firebase interaction is and what solutions are currently available.
dosstx commentedon Feb 11, 2023
I am having the same problem, but also when I ran
npm ifrom the.output/serverdirectory as mentioned above, I get the following error:Anyone have any ideas? My app is offline now because of this and can't deploy Nuxt server function to firebase!
DevJoghurt commentedon Feb 13, 2023
@dosstx
Yes, it could be that the workaround with
npm installhas edge cases that provoke such errors. Might be because the tracing of nitro is not meant to install via npm afterwards.I have written a node script that I have attached in the firebase.json as predeploy:
Simply save this code in the root directory as a deploy.js file and add the deploy script to your firebase.json file:
{ "functions": [{ "source": ".output/server", "predeploy": "node ./deploy.js" }], "hosting": [{ "site": "your-site", "public": "./app/.output/public", "cleanUrls": true, "rewrites": [ { "source": "**", "function": "server" } ] }] }So i was able to work around the tracing bug and maybe it fixes your bug as well.
If not, it is more likely a bug in nitro or nuxt and you should create a bug report there.
dosstx commentedon Feb 13, 2023
Thank you! Will give it a shot! @DevJoghurt
dosstx commentedon Feb 27, 2023
I was able to fix this, but all I did was delete my functions directory and do a
firebase init --only functionsand it fixed all the issues for me. Of course, I am also using codebases format so myfirebase.jsonlooks like so:jamesdaniels commentedon Apr 12, 2023
This should now work with the source option:
{ "functions": [ { "source": "functions", "codebase": "functions", "ignore": [ "node_modules", ".git", "firebase-debug.log", "firebase-debug.*.log" ] } ], "hosting": [ { "site": "<removed>", "source": "." } ] }desk-pro commentedon Apr 20, 2023
@jamesdaniels Could you please give more insight about your fix ? I don't understand what
"source": "."does.CharlieDigital commentedon Jun 14, 2023
@dosstx's sample worked for me; however if I move the Nuxt application down from the root directory into a
/webdirectory, the error returns again.So if my path is like this:
/web/.output/server. it doesn't work. If I have my output at.output/server(all Nuxt artifacts at the root of the project), everything works.CharlieDigital commentedon Jun 15, 2023
@desk-pro The
"source": "."appears to be part of the new experimental Web Frameworks feature.https://firebase.google.com/docs/hosting/frameworks/frameworks-overview
The way I can get it to work is the following:
firebase init, it will detect the Nuxt appfirebasenitro preset; if you use the preset, it will generate annpm packerror.To answer your question, the
"source": "."points the CLI to the working directory where the Nuxt app exists (where thenuxt.config.tsis sitting).NOTE: From my own experimentation, it doesn't seem to support using any nested directory like
/nuxt-appfor example. This generates a different type of error when deploying.I have a sample repo here: https://github.com/CharlieDigital/nuxt3-firebase
And the app running here:
Still working out some kinks; hoping the documentation gets updated.
typefox09 commentedon Sep 24, 2023
How did you go with this? I noticed when doing this with VueFire auth you get this error on build:
[nuxt] [request error] [unhandled] [500] Failed to parse service account json file: Error: Service account object must contain a string "project_id" property.
CharlieDigital commentedon Sep 24, 2023
The VueFire error is because it's trying to run the Firebase client on the server and fails.
The gist of the workaround for this error is to isolate the Firebase dependent code to only run on the client. You can use a variety of techniques for this.
The easiest: if the page doesn't need server rendering, then set
routeRuleswith{ ssr: false }for the route. If the page requires server rendering, you'll need to isolate the client dependency using Nuxt<ClientOnly/>: https://nuxt.com/docs/api/components/client-only (move the Firebase dependent code into a component and only load that component on the client).typefox09 commentedon Sep 24, 2023
But I'm checking auth and fetching Firestore results server side? I need this for key landing pages for SEO.
The build currently works when running the buiild normally and deploying it without Firebase's new experimental hosting feature. Although you mentioned when you nested the project you have issues (ie /nuxt-app), I'm wondering If this is the issue as I'm doing the same in a monorepo
CharlieDigital commentedon Sep 24, 2023
On the server side, you use the Admin SDK. But the problem is that if you are running your code with SSR and it's loading the client SDKs as well, you'll get the error.
So in your SSR routes, you need to isolate the client SDKs from the server SDKs and ensure that the SSR routes don't load the client SDKs.
typefox09 commentedon Sep 24, 2023
CharlieDigital commentedon Sep 24, 2023
If you look carefully the output of the build process, the new Firebase Hosting Web Frameworks is effectively generating a Function that is very similar to what the Nuxt Firebase build preset does. They are somewhat interchangeable.
superdiazzz commentedon Mar 6, 2024
Any solution? i have tried some answers above but still fail? My last attempt was performing
firebase init functionsit makes my firebase.json like so,it created new folder functions but when doing deploy still return error. Console error said,
CharlieDigital commentedon Mar 6, 2024
@superdiazzz Can you verify that there is actually output at
.output/server/index.js?superdiazzz commentedon Mar 6, 2024
@CharlieDigital
I think i was in wrong way, so i tried another way with this tutorial. I get back from beginning and make my firebase.json below:
i change my nuxt.config.ts
then run this scrip in package.json
"deploy-fb": "cd .output/server && rm -rf node_modules && npm i && cd .. && firebase deploy",But, sadly it failed with no clue ;(
it just said like so,
