Deployment error firebase hosting - 0 files found

227 views Asked by At

Description:

During the deploy of firebase hosting, I received an error stating that 0 files were found. I have included my firebase.json file for reference.

Steps to reproduce:

Run the command firebase deploy --only hosting

Observe the error message stating that 0 files were found

Expected result:

The firebase hosting should be successfully deployed with the specified files.

Actual result:

An error is thrown stating that 0 files were found.

+  hosting: Finished running predeploy script.
i  hosting[hosting-project]: beginning deploy...
i  hosting[hosting-project]: found 0 files in hosting
+  hosting[hosting-project]: file upload complete
i  hosting[hosting-project]: finalizing version...
+  hosting[hosting-project]: version finalized
i  hosting[hosting-project]: releasing new version...
+  hosting[hosting-project]: release complete
+  Deploy complete!

Notes:

  • I have double-checked the file path in the firebase.json file and it appears to be correct.
  • I have tried rerunning the deploy command multiple times with the same result
  • I have also tried deploying a different project with the same firebase.json file, but the issue persists.
  • In my firebase.json file, I am not targeting the dist folder directly because I am using the predeploy script to run npm run lint and npm run build before the deployment. However, I am not ignoring the dist folder with !dist% and !dist/*, which means I am not excluding it from the deployment.

Attached files:

firebase.json

{
  "firestore": {
    "port": "8080"
  },
  "functions": [
    {
      "source": "functions",
      "codebase": "default",
      "ignore": [
        "node_modules",
        ".git",
        "firebase-debug.log",
        "firebase-debug.*.log"
      ],
      "predeploy": [
        "npm --prefix \"$RESOURCE_DIR\" run lint"
      ]
    }
  ],
  "hosting":{
    "public":"hosting",
    "ignore": [
      "*",
      "!dist/",
      "!dist/*",
    ],
    "rewrites":[
      {
        "source":"**",
        "destination":"dist/index.html"
      }
    ],
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint",
      "npm --prefix \"$RESOURCE_DIR\" run build"
    ]
  }
}
1

There are 1 answers

0
Fasco On

I found a solution to resolve the issue of "0 files found" during the deploy of firebase hosting. It may not be the most elegant solution, but it does work. In the "predeploy" section of the hosting configuration, I added ".." at the end of the "npm run lint" and "npm run build" commands to go back to the root folder:

"npm --prefix \"$RESOURCE_DIR\\..\" run lint",
"npm --prefix \"$RESOURCE_DIR\\..\" run build"

This allowed me to target the dist folder directly in the hosting configuration, as specified in the official documentation. Here is the modified hosting configuration:

"hosting":{
    "public":"hosting/dist",
    "ignore": [
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites":[
      {
        "source":"**",
        "destination":"/index.html"
      }
    ],
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\\..\" run lint",
      "npm --prefix \"$RESOURCE_DIR\\..\" run build"
    ]
  }

I hope this helps anyone else who may be experiencing the same issue.