Next.js: Assets not loading on GitHub Pages with Custom Domain

Created on 10 Aug 2019  Â·  4Comments  Â·  Source: vercel/next.js

Bug report

Describe the bug

I'm hosting my exported static page on gh-pages with a custom domain.

Error shown is as follows:

The script from “http://___.co/_next/static/runtime/webpack-f5e50b6b501ccea2a79b.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type.
Loading failed for the <script> with source “http://___.co/_next/static/runtime/webpack-f5e50b6b501ccea2a79b.js”.

Images are loaded fine. It's only hashed files which don't work.

To Reproduce

Export and push to gh-pages.

Expected behavior

Site renders properly and loads all assets as it should.

System information

  • gh-pages
  • Ubuntu
  • .nojekyll and CNAME added.

Most helpful comment

If you are having a similar problem and found this issue, here is what solved my problem.

Had a similar problem, on my case it was the .nojekyll file missing. I tried fixing adding it right after generating the static assets:

  "scripts": {
    ...
    "static": "next build && next export && touch ./out/.nojekyll && echo 'evandro.sasse.it' > ./out/CNAME",
    ...
  },

The link @timneutkens posted doesnt work anymore, but you can find more information on this issue: https://github.com/zeit/next.js/issues/2029.

BUT...

I am also using gh-pages to send the files from the out folder to the branch Github Pages will serve, by default the .nojekyll file was not being saved there. You can use the option -t true to circumvent this behaviour. More info on this issue https://github.com/tschaub/gh-pages/issues/315. My deploy script looks like this now:

  "scripts": {
    ...
    "deploy": "gh-pages -d out -t true"
    ...
  },

All 4 comments

I'm guessing it's related to this note? https://github.com/zeit/next.js/wiki/Deploying-a-Next.js-app-into-GitHub-Pages#extra-step-for-project-page-sites

This doesn't sound like a particular bug with Next.js, more-so hosting configuration side. Might be interesting to look into hosting on https://zeit.co.

I don't think it is related to the assetPrefix because I'm using a custom domain. Should be under /_next then, no?

It could be a problem on the host. But if gh-pages is part of the documentation, it should work, shouldn't it?

@leon-wbr have you solve it?

I've got the same problem. You can check it under:
https://mariowski.pl/ (check console) & https://github.com/Xandev/my-website/

If you are having a similar problem and found this issue, here is what solved my problem.

Had a similar problem, on my case it was the .nojekyll file missing. I tried fixing adding it right after generating the static assets:

  "scripts": {
    ...
    "static": "next build && next export && touch ./out/.nojekyll && echo 'evandro.sasse.it' > ./out/CNAME",
    ...
  },

The link @timneutkens posted doesnt work anymore, but you can find more information on this issue: https://github.com/zeit/next.js/issues/2029.

BUT...

I am also using gh-pages to send the files from the out folder to the branch Github Pages will serve, by default the .nojekyll file was not being saved there. You can use the option -t true to circumvent this behaviour. More info on this issue https://github.com/tschaub/gh-pages/issues/315. My deploy script looks like this now:

  "scripts": {
    ...
    "deploy": "gh-pages -d out -t true"
    ...
  },
Was this page helpful?
0 / 5 - 0 ratings

Related issues

DvirSh picture DvirSh  Â·  3Comments

jesselee34 picture jesselee34  Â·  3Comments

pie6k picture pie6k  Â·  3Comments

havefive picture havefive  Â·  3Comments

wagerfield picture wagerfield  Â·  3Comments