1

I am having an error with Svelte that prevents the loading of bundle.js, bundle.css, global.css and favicon.png on a website hosted on GitHub pages.

I have read through this question but the issue persists on other browsers, without any VPN, a clean Firefox profile or no extensions, and seems to be an issue with the acceptance of the content-type of the files.

The error message in the Firefox console is:

GET https://path/to/global.css    [HTTP/2 404 Not Found 9ms]

GET  https://path/to/bundle.css   [HTTP/2 404 Not Found 9ms]

GET https://path/to/bundle.js     [HTTP/2 404 Not Found 7ms]

Loading failed for the <script> with source “https://path/to/bundle.js”

GET https://path/to/favicon.png   [HTTP/2 404 Not Found 7ms]

And the Network tab returns: network tab

With the response and request headers for favicon.png:

// Request

GET /favicon.png HTTP/2
Host: kitchefs.github.io
User-Agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0
Accept: image/webp,*/*
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Referer: https://kitchefs.github.io/beta/
TE: Trailers

// Response

HTTP/2 404 Not Found
content-type: text/html; charset=utf-8
server: GitHub.com
strict-transport-security: max-age=31556952
etag: W/"5f4de496-313"
access-control-allow-origin: *
content-encoding: gzip
x-proxy-cache: MISS
x-github-request-id: EAA2:03EC:1BFD04:221937:5F816340
accept-ranges: bytes
date: Sat, 10 Oct 2020 07:39:07 GMT
via: 1.1 varnish
age: 475

The other response headers all show the content-type type of text/html, despite all of them not accepting text/html.

I'm using GitHub pages on a gh-pages branch, and I can confirm that the files exist. I'm wordering if this is an issue with GitHub pages or Svelte and what I can do to fix/prevent this problem from occuring in the future.

If required, here is the code and the website can be accessed at https://kitchefs.github.io/beta.

3 Answers 3

2

Remove the leading / in your public/index.html:

<link rel='icon' type='image/png' href='favicon.png'>
<link rel='stylesheet' href='global.css'>
<link rel='stylesheet' href='build/bundle.css'>
<script defer src='build/bundle.js'></script>

Gh-pages will be resolved with your repos name in the URL. Thus you are not on base path.

https://kitchefs.github.io/beta/

6
  • Thank you, this works. Is there any way you know of to configure Svelte or use some Github Action to do this automatically, or will I have to edit it manually every time? Commented Oct 10, 2020 at 9:59
  • 1
    I created a 'static' index.html inside the public folder. (added to git). This works for me. As example see: github.com/ivosdc/svelte-generic-crud-table ...dist folder. I'm using travis.ci for deploying gh-pages
    – nologin
    Commented Oct 10, 2020 at 10:02
  • Wow - why did it take me so long to find this - thank you! I wonder why svelte apps don't come packaged with this change to begin with.
    – jajabarr
    Commented Apr 1, 2021 at 4:37
  • I tried changing the url like you said, first by replacing the leading / with "./" and then removing it. In all cases I get the error: GET https://<gitproject>/_app/immutable/assets/index-8cccb8e7.css net::ERR_ABORTED 404
    – SamHeyman
    Commented Aug 9, 2022 at 9:48
  • Also need help, I have the same problem as @SamHeyman
    – Fasteroid
    Commented Oct 19, 2023 at 7:48
1

I followed this guide: https://sveltesaas.com/articles/sveltekit-github-pages-guide/

It recommends using the docs folder as build folder (via svelte.config.js) and setting up GitHub Pages to host from the docs folder.

I tried to host from the root folder in GitHub Pages, but just got the 404 error messages. Using the docs folder solved the issue.

1

I understand that there is already an accepted answer, but the fix didn't help me. What worked for me was this.

Turns out that the problem is that in my svelte.config.js I had paths: { base: dev ? '' : '/my-portfolio', } because it was needed by GitHub in order to make it work. Apparently now it doesn't need it anymore, so all the 404 were right since it was trying to get non-existing files.

https://github.com/orgs/community/discussions/52062

Try removing the paths that you might have configured in svelte.config.js

Not the answer you're looking for? Browse other questions tagged or ask your own question.