0

I am experimenting with dynamic routing on static site hosting services like github pages. I understand that normally you wouldn't want to do this and may have to jump through hoops to get it working.

I am using onMount function from svelte to load the data on the client side. I have two dynamic urls, /qna?id=1, this works but the other url /blog/[slug] fails. When I navigate to a url like /blog/hello, it returns the following error in console: Uncaught (in promise) TypeError: Failed to fetch dynamically imported module: https://mohit2152sharma.github.io/_app/immutable/entry/start.a84ced15.js. My guess is this being caused by some path issue. If anyone has encountered similar issue, would appreciate your help and time.

(You can check out the repo here: https://github.com/mohit2152sharma/svelte-mpa-example)

PS: I have followed almost all the steps mentioned in the docs, like setting up csr=true and ssr=false, using adapter-static, using fallback='404.html' which is same as that of github pages error page.

PPS: If I deploy the same project on vercel it works, the only changes I make while deploying are change the adapter to adapter-vercel and use the defaults for adapter.

0

1 Answer 1

3

It looks like you are not configuring or using the repository as base path correctly. The repository name is missing between domain and _app in the requested path:

https://mohit2152sharma.github.io/_app/immutable/entry/start.a84ced15.js

This much is noted in the GitHub Pages specific docs:

When building for GitHub Pages, make sure to update paths.base to match your repo name, since the site will be served from https://your-username.github.io/your-repo-name rather than from the root.

Also think there used to be something in the docs about issues around Jekyll and directories prefixed with _. By default, code ends up in _app as seen in the error and that was not be served. Maybe not an issue anymore.
Would disable Jekyll by putting a .nojekyll into the root of the pages branch and change the output directory (appDir) to something different.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for pointing me in the right direction. I was able to solve it by setting paths.asset in svelte config to my github.io url including repo name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.