Search code examples
reactjscreate-react-appgithub-pagesnetlifynpm-package

Deploying a react app on hosting platforms (github pages, netlify)


I have created a portfolio website using react, create-react-app with typescript template. I was trying to deploy it on github pages following this, but I keep getting an error you need to enable Javascript on your browser. I have tried following several things but nothing really works, it just shows a blank white page.

After this I tried Netlify, it starts the deployment but fails on a local package that must be installed. I was trying to use a react package from npm which was missing a customisation so I made the changes in code and use the build as a local npm package in my source code. Error: Module not found: Error: Can"t resolve "react-chrono" in "/opt/build/repo/src/timeline".

I can run and build it fine on my machine.

Link to my github repository.

TLDR; Deploying a react app on github pages or netlify(when you have a local npm package).


Solution

  • Anyone trying it on github pages, in your package.json file set the homepage property to '.' instead of https://{username}.github.io. If you try and run the static build locally and check index.html, all stylesheet and script paths start with your homepage and it mess up the imports.