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
The
"source": "."
in yourfirebase.json
tells Firebase that the web site exists in the directory where thatfirebase.json
file resides. The error message indicates that it doesn’t actually exists there.You’ll want to update your
firebase.json
so that thesource
points to the output of your flutter build.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
the final firebase.josn looks like this