Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Cloud Functions cannot read nitro generated index.mjs file

EDIT:

I want to deploy a Nuxt3 app to Firebase Hosting. I've set the deployment preset for Nitro to "firebase" NITRO_PRESET=firebase, and the build step works fine. However, when I run firebase deploy, I get an error saying:

There was an error reading .output/server/package.json: 
.output/server/index.js does not exist, can't deploy Cloud Functions

I checked the .output/server directory, and saw that Nitro generated a file called index.mjs. I checked to see if Cloud Functions also works with .mjs files, but that doesn't seem to be the case. I looked for possible solutions but couldn't find anything; I tried reinstalling my modules, but no luck. Do I have something misconfigured or broken?

I'm following this tutorial: https://nitro.unjs.io/deploy/providers/firebase

I'm using WSL2 Ubuntu on Windows 11, and the project folder is inside the linux filesystem.

Here is my package.json:

{
  "private": true,
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview"

  },
  "devDependencies": {
    "@nuxtjs/google-fonts": "^3.0.0-0",
    "@types/three": "^0.143.1",
    "nuxt": "3.0.0-rc.8"
  },
  "dependencies": {
    "firebase": "^9.9.3",
    "sass": "^1.54.5",
    "three": "^0.143.0",
    "vuex": "^4.0.2",
    "sass-loader": "^13.0.2"
  }
}

My firebase.json:

{
  "functions": {
    "source": "./.output/server",
    "runtime": "nodejs16",
    "ignore": [
      "node_modules",
      ".git",
      "firebase-debug.log",
      "firebase-debug.*.log"
    ]
  },
  "hosting": {
    "site": "my-site",
    "public": ".output/public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "cleanUrls": true,
    "rewrites": [
      {
        "source": "**",
        "function": "server"
      }
    ]
  }
}

After the build step:

Σ Total size: 19.6 MB (3.21 MB gzip)
✔ You can deploy this build using npx firebase deploy                 

After the deployment step:

i  deploying functions, hosting
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
i  artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
✔  functions: required API cloudbuild.googleapis.com is enabled
✔  functions: required API cloudfunctions.googleapis.com is enabled
✔  artifactregistry: required API artifactregistry.googleapis.com is enabled
i  functions: preparing codebase default for deployment

Error: There was an error reading .output/server/package.json:

.output/server/index.js does not exist, can't deploy Cloud Functions
like image 422
Apricitine Avatar asked Dec 21 '25 20:12

Apricitine


1 Answers

It seems you are using the default node-server preset. To deploy the Nuxt 3 app to Firebase, you must set the NITRO_PRESET to firebase in your environment.

NITRO_PRESET=firebase

npm run build 

The CLI should prompt you to run npx firebase deploy once the build is completed.

enter image description here

Then run the command and it will deploy the application to Firebase hosting and functions.

You can read more about this in the documentation.

like image 124
Dharmaraj Avatar answered Dec 23 '25 17:12

Dharmaraj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!