2

I made a simple React app in Visual Studio Code and want to host it on a website which I am using surge.sh. When I deployed the app and head to the site, it just shows a blank page although the deployment was successful when I deploy it in my terminal.

Here are my steps that I did:

  1. cd to root directory of my project
  2. run npm run build
  3. cd build
  4. run surge command
  5. provide {domain name}.surge.sh

I am new to using surge.sh. What might I have done wrong?

halfer
  • 19,824
  • 17
  • 99
  • 186
Daredevil
  • 1,672
  • 3
  • 18
  • 47
  • any errors in build process? – Rikin Sep 06 '19 at 17:23
  • @Rikin No errors. The way I fixed it was to follow the above steps but with the addition of renaming the `index.html` to `200.html` and the it works. No idea why. – Daredevil Sep 07 '19 at 06:58
  • @Daredevil It should still have showed up at the root, but then the 200.html file also indicates that you want all routes to redirect to the index, because you’re managing the routing client side. More details are here: https://surge.sh/help/adding-a-200-page-for-client-side-routing – kennethormandy Sep 21 '19 at 21:06

3 Answers3

0

Follow below step to resolve(only 4 surge):

npm run build
cd build
cp index.html 200.html
surge
0

You could add the following to your package.json scripts -

"scripts": {
   ...
   "deploy": "npm run build && cp build/index.html build/200.html && surge build https://{domain_name}"
}

And then you can run this on a Terminal from the root of the project (anytime you need to deploy) using npm run deploy.

Shalom Sam
  • 1,539
  • 1
  • 16
  • 26
0

This solution works for my React projects, even with Router.

https://www.geeksforgeeks.org/how-to-deploy-react-app-to-surge/

I deleted strings "homepage", "deploy", "pre-deploy" in file package.json, built static version with 'npm run build', run 'surge', added 'build' to project path, added the project name

and BINGO! that's worked! no more blank screens and paths to-from who-knows-where

Projects was build as create-react-app in VS code