skip to Main Content

I am having an issue when I refresh my flutter webapp and it says

This file does not exist and there was no index.html found in the current directory or 404.html in the root directory.

Why am I seeing this?
You may have deployed the wrong directory for your application. Check your firebase.json and make sure the public directory is pointing to a directory that contains an index.html file.

You can also add a 404.html in the root of your site to replace this page with a custom error page."

I will add the JSON I currently use.

I don’t know if its something else or my JSON code

{
 "hosting": {
   "source": ".",
   "ignore": [
   "firebase.json",
     "**/.*",
     "**/node_modules/**"
   ],
   "frameworksBackend": {
     "region": "us-central1"
   }
 },
 "functions": [
   {
     "source": "functions",
     "codebase": "default",
     "ignore": [
       "node_modules",
       ".git",
       "firebase-debug.log",
       "firebase-debug.*.log",
       "*.local"
     ],
     "predeploy": [
       "npm --prefix "$RESOURCE_DIR" run lint"
     ]
   }
 ]
}

2

Answers


  1. The "source": "." in your firebase.json tells Firebase that the web site exists in the directory where that firebase.json file resides. The error message indicates that it doesn’t actually exists there.

    You’ll want to update your firebase.json so that the source points to the output of your flutter build.

    Login or Signup to reply.
  2. I faced the same problem when refreshing while in base_url/path

    to clarify things

    com.example -> refresh works.

    com.example/page1 refresh (page not found)

    after searching, I found it’s related to go_router
    when using urlPathStrategy

    and I solved it by adding this to firebase.json in rewrites

    {
        "source": "**",
         "destination": "/index.html"
     }
    

    the final firebase.josn looks like this

    {
      "hosting": {
        "public": "build/web",
        "rewrites":[
          {
            "source": "**",
             "destination": "/index.html"
         }
        ],
        "ignore": [
          "firebase.json",
          "**/.*",
          "**/node_modules/**"
        ],
        "frameworksBackend": {
          "region": "europe-west1"
        }
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search