Diego Simonelli
Diego Simonelli

Reputation: 35

Why my React app is not loading correctly (broken) in localhost?

I had my react project working correctly in localhost. Then, I decided to deploy it to github pages and it worked perfectly on the server too. Now, I'm trying to work on it again on localhost but it is not showing correctly. For some reason, photos are not loading and some css is not working correctly and after compile it in PowerShell says this:


Compiled successfully!

You can now view myportfolio in the browser.

Local: http://localhost:3000/myportfolio

On Your Network: http://192.168.56.1:3000/myportfolio

Note that the development build is not optimized.

To create a production build, use npm run build.

So if I go to my GitHub pages it is loading correctly but not in localhost (running npm start).

Any suggestion? Thank you in advance and let me know if you need more clarification

Upvotes: 0

Views: 5328

Answers (1)

ABGR
ABGR

Reputation: 5205

I did clone your repositories and found these problems:

  1. You have been directly imported many third-party js given their relative path in the index.html. That doesn't work. You should append %PUBLIC_URL% before them. For e.g.

    <script src="%PUBLIC_URL%/js/jquery.flexslider.js"></script> and similary for other script files.

  2. But even this is not the best that you can do. You must not try to use jquery or third party js in a React App. Also, make it a part to install the related JS though npm and make them a part of the package.

  3. You'll have to use <img src={require('/public/images/background.png')}... (Btw, the image name on your gh-pages is different. It's logo.png there)if you want the webpack to compile and make it a part of your project. Also, the path must reside within src and not public folder.

  4. Other errors are are related to keys. Whenever you're mapping and iterating through a list in react you must specify a unique key.

Upvotes: 2

Related Questions