Can't load three.js animations after deploying it on Github

Viewed 42

I made a basic portfolio website using main.js It works fine on the local server but when I upload the code to GitHub and deploy it, it doesn't work.

I only see HTML and CSS files but the main.js files won't load. I even tried using gh-pages and creating a dist folder but it still doesn't work.

My console has the following error:

THREE.WebGLRenderer: A WebGL context could not be created.

How can I fix this? Here's my code

1 Answers
<script type="module" crossorigin src="/assets/index.548483ff.js"></script>
<link rel="stylesheet" href="/assets/index.4db4f50e.css">

Both paths are not correct. You want to use:

<script type="module" crossorigin src="./assets/index.548483ff.js"></script>
<link rel="stylesheet" href="./assets/index.4db4f50e.css">

The additional dot ensures the path starts relative from the current location and not from the host.

Related