0

I am trying to add Hosting to an existing firebase app that has Functions up and running. I intended to host a react app that consume my existing functions. The public directory I chose for hosting is /{react-project-root-folder}/build.

I followed this answer to add hosting.

When I am running firebase deploy, it gives the error

Error: Specified "public" directory "/view/build" does not exist, can't deploy hosting to site {app-name}

Even though the folder exists.

Can you help me spot what I did wrong? Should I choose another folder?

My folder structure:

Firebase Practice
|__ functions
|__ .firebase.json
|__ .firebaserc
|__ view
    |__ build
        |__ static/js
        |__ index.html
    |__ node_modules
    |__ public
    |__ src

Image of folder structure:

enter image description here

firebase.json:

{
  "functions": {
    "ignore": [
      "node_modules",
      ".git",
      "firebase-debug.log",
      "firebase-debug.*.log"
    ],
    "source": "functions"
  },
  "hosting": {
    "public": "/view/build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "/api/*",
        "function": "api"
      },
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

1 Answers1

1

Turn out you do not need the first / on your public path.

Corrected firebase.json:

{
  "functions": {
    "ignore": [
      "node_modules",
      ".git",
      "firebase-debug.log",
      "firebase-debug.*.log"
    ],
    "source": "functions"
  },
  "hosting": {
    "public": "view/build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

  • 1
    Leading with a `/` makes the CLI consider it an absolute path (starting from the root). This meansit can likely not find the path, but even if it can, it will then complain about the `/view/build` directory being outside of the project home directory (where your `firebase.json` file is). :) – Frank van Puffelen Sep 14 '22 at 00:52