0

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

12
  • What does your console say? are there any errors such as can not load resources Commented Jun 1, 2020 at 5:55
  • @RahulDwivedi No errors at all. It is still working fine on github pages but in localhost my css is messed up. Commented Jun 1, 2020 at 18:39
  • Do you get any errors on console on your local machine? Can you share the guthub link? Commented Jun 1, 2020 at 18:55
  • @RahulDwivedi I'm a React beginner so from what I know I don't see any errors in console neither. Sure the project github link: github.com/diegosimonelli/myportfolio Commented Jun 1, 2020 at 19:10
  • Is it deployed on github pages? Commented Jun 1, 2020 at 19:14

1 Answer 1

2

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.

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

1 Comment

Thank you for all the help! I really appreciate it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.