gatsby: github pages 404 error on static files first time

I am new to gatsby and facing an issue with loading static html files.

I have a component called notes.js that links to some static files like so

export default ({ data }) =>
  <div style={{ flex: "1 0 auto" }}>
    <Link to={withPrefix("/notes/note1.html")} target="_blank">some note</Link>
  </div>

The file is saved at static/notes/note1.html. This works fine in development, http://localhost:8000/notes/note1.html opens as expected when I click on the link. But when I deploy the same, the first time I click on the link, it goes to github’s 404 page. But works fine on subsequent clicks.

Have I misconfigured something in gatsby? gatsby repo: https://github.com/subsid/blog-skeleton

Thanks for your great work.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 24 (12 by maintainers)

Most upvoted comments

This is a mistake…

@SleeplessByte I added target=“_blank” and href to http instead of https. It used to give 404 on primerlabs.io, but worked well on www.primerlabs.io. Now, it’s working fine for both.

not stale

On Sat, 19 Jan 2019, 18:16 gatsbot[bot], notifications@github.com wrote:

Old issues will be closed after 30 days of inactivity. This issue has been quiet for 20 days and is being marked as stale. Reply here or add the label “not stale” to keep this issue open!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/gatsbyjs/gatsby/issues/4115#issuecomment-455797990, or mute the thread https://github.com/notifications/unsubscribe-auth/AB35WJepN3LdQ5tlc6H4NRcSj-LS6g4gks5vE1MLgaJpZM4SJiys .

I’m also facing the same issue, my question is how do you handle the already existing service worker to fix this issue or force refresh to update the changes.

@ykosaka-welyco when you updated navigateFallbackWhitelist did you manage to test on a different browser where the service worker hadn’t been updated yet?

Yup, that solves the issue. Disabling gatsby-plugin-offline seems to cause someother error to do with sw.js when deployed. (might be cause of my chrome extensions as well) It worked fine on firefox though. Anyways, I’ll dig into this a little more and see if I can get more info. Thanks!

screen shot 2018-02-19 at 12 37 50 pm

Huh… ok! I’m not sure exactly what’s happening under the hood, but I managed to work around this with these steps:

  • rename your /static/notes/ directory to something else - I chose /static/static-notes
  • update the links with the above new path
  • disable gatsby-plugin-offline

Does that fix it on your side? If you’re able to do some more digging into the source of the problem that’d be very useful!

Hi @peduarte 👋 that suggestion was for @subsid, I don’t know if it’ll help in your case. Could you create a new GitHub issue explaining the error you’re seeing?