Dylan Wain
Dylan Wain

Reputation: 21

Flutter web on Firebase Hosting showing "Page Not Found" when I refresh the webapp

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"
     ]
   }
 ]
}

Upvotes: 2

Views: 779

Answers (3)

Abdullah Alamodi
Abdullah Alamodi

Reputation: 349

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.

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

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

the final firebase.json looks like this:

{
  "hosting": {
    "public": "build/web",
    "rewrites":[
      {
        "source": "**",
         "destination": "/index.html"
     }
    ],
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "frameworksBackend": {
      "region": "europe-west1"
    }
  }
}

Upvotes: 2

Code on the Rocks
Code on the Rocks

Reputation: 17764

For some reason, the flutter build web command failed to generate an index.html file in the build/web folder the first time I ran it so when I deployed to firebase the file was missing.

I re-ran the flutter build command and the index file showed up. The moral of the story is to double check the index.html file is getting generated:

enter image description here

Upvotes: 1

Frank van Puffelen
Frank van Puffelen

Reputation: 599601

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.

Upvotes: 1

Related Questions