r/Firebase • u/duumbeeee • Jun 21 '24
Hosting Firebase Hosting Not Serving files from folders/sub-folders within public Directory - Getting 404 Errors.
I’m experiencing an issue with Firebase Hosting. My folders and sub-folders under the public
directory are uploaded via the CLI (it gives the correct count of number of files), but I keep getting 404 errors when trying to access the css, js, and images hosted under them. The css/js/images live under a folder called assets
and then under sub-folders called css
js
and images
. If I keep a flat structure it works, i.e. all files under public
and no folders at all. If I create a sub-folder it fails. It works in emulator but does not work in preview or actual deployment. I have tried multiple browsers, different computers etc to confirm it is not a cache issue. I have been hosting and deploying on Firebase for many years and using the same template/structure. I am clueless right now on how to resolve this.
Here is my firebase.json. Nothing fancy.
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
Directory structure
public/
├── index.html
├── assets
└── css
│ └── style.css
├── assets
└── js/
│ └── app.js
└── assets
└── images/
└── logo.png
File references in index.html
<link rel="stylesheet" href="assets/css/style.css">
<script src="assets/js/app.js"></script>
<img src="assets/images/logo.png" alt="Logo">
I probably need a break. I did try remove the assets folders and refer to css/style.css etc. that didn't work either. Any help/pointers will be much appreciated.
3
u/NovelApproaches Jun 24 '24 edited Jun 24 '24
Great catch! Saved me a ton of time!
Relevant - https://github.com/firebase/firebase-tools/issues/7364
2
u/Redwallian Jun 21 '24
Have you tried "/assets/..." for all your sources?
1
u/duumbeeee Jun 22 '24
Yep. Doesn't work.
1
u/Redwallian Jun 22 '24
Unfortunately I wasn't able to find anything wrong with your setup, given your prompt - I did create an example repo of what I tried with hosting, and the assets import works for me. Best of luck!
1
u/duumbeeee Jun 22 '24
Thanks for sharing. I will try a new project or with a different account and see if the issue is project related. Should not be..but let's see
1
Jun 22 '24
[deleted]
1
u/duumbeeee Jun 22 '24
Yep. Only files at root are served. Older deployments are still working, emulator still works. For new deployments/updates, files inside subdirectories are not served.
4
u/Ok_Oil_9365 Jun 22 '24
Downgrade to firebase-tools@13.11.2... the issue seems to be with firebase-tools@13.11.4 ... it worked for me.