12

I am wondering if it is possible to deploy react.js web app that I've built to a share hosting site that does not have node.js installed?

I use webpack to build the application and it creates normal html, js, css file. I uploaded the static folder that includes all those html, js(bundle.js) and css files, but when I request the site, the server reply with 404 bundle.js not found response.

1
  • Yes the site should work. You just need to make sure your host is serving your static files correctly and also the path in your index.html is referencing the correct bundle.js url. Commented Mar 10, 2017 at 19:07

3 Answers 3

13

Yes you sure can put react on a shared hosting provider.

Seeing as you're getting a 404 error (not found), you are probably referencing your react file/bundle incorrectly. It might not even be named bundle.js if you're using a boilerplate to create your application.

Can you give more information? What does your index.html file look like? What does your directory structure look like? If you are able to post these files I can tell you what the issue is.

Update: The answer below should be accepted. (Although this would assume that you have the ability to make a build which you have not verified or not.)

Make a build using the build command through whatever boilerplate you used. Deploy those files on your shared hosting server. Make sure that index.html is at the root of where your server is expecting the root to be and your app should be live.

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

Comments

13

Use npm run build, you should get a folder with the index html file inside that will run your app. Try this with xampp first before you actually deploy to your server.

Here is everything step by step

npm run build

or

yarn run build

it will generate a build folder that looks like this:

enter image description here

Copy everything and move it to the htdocs in xampp or ftp upload the directory to the public_html file in your hosting

Comments

3

For deploying a react app on a shared hosting you need to create a production build. Production build is a pack of all your react code and its dependencies.

in most shared hosting we put our site/app inside a public_html directory so if we hit www.yourdomain.com it serves the code from public_html directory.

so if your react app is ready to go, edit your package.json file add a new key value:

"homepage":"http://yourdomain.com"

then create a build using following command:

npm run build

after running the command you will see a new directory named build in your app root. It will contain js and css for the app and a index.html file. You need to upload all the content inside build directory to public_html directory, and that's all, go to your domain and your app will be working just fine.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.