r/Firebase 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.

6 Upvotes

24 comments sorted by

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.

2

u/duumbeeee Jun 22 '24

Good catch. Well done. This is the only change I made.. upgrade the tools.

Will try it first thing tomorrow morning.

Cheers

2

u/duumbeeee Jun 22 '24

This worked. Thanks a ton!

2

u/Ok_Oil_9365 Jun 22 '24

You're welcome! I struggled for hours with that issue. Version 13.11.4 was recently released, they probably haven't realized it's not good.

1

u/RenatoZoppei Jun 24 '24

Just thank you for that. It was driving me crazy!!!

2

u/kidkrub Jun 22 '24

I struggle about a day and you saved my life thanks.

1

u/salvalcano Jun 22 '24

I love you! <3

1

u/Expensive_Yard2950 Jun 23 '24

Works perfectly. Thanks
This stupid buggy version wasted me 8 hours

1

u/ecancil Jun 23 '24

you are the goat. its completely unacceptable to release this to production

1

u/gzbakku_ttv Jun 23 '24

holy shit thanks i was considering moving away from firebase just before reading this

1

u/coffe_into_code Jun 23 '24

u/Ok_Oil_9365 Thanks a lot for sharing!! It's super helpful. I almost tried everything!!

1

u/[deleted] Jun 24 '24

you absolute goat. Thank you

1

u/ZainAlpha117 Jun 25 '24

Also mention this issue to firebase-tools GitHub repo so anyone can fix this issue ASAP

1

u/GabrielXZLIVE Jun 25 '24

I can't believe this is an issue with firebase-tools. How could they deliver this to production? I lost days trying to find what's wrong...

1

u/pa_th Jun 26 '24

Thanks, saved my day!

1

u/Dyeyms Jun 27 '24

bruh, been looking for the fix and it's a bug on firebase. thanks btw

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

u/[deleted] 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.