1

When I'm trying to open React page using links like http://www.bla.com/sdfsf everything work as It should, but when I'm trying to reach the site using the url http://www.bla.com/sdfsf/asdad it fails returning me the error:

Uncaught SyntaxError: Unexpected token <

I've done few researches on this topic, people who had a similar problem solved it by adding property type="text/jsx" or type="text/babel" to their script tag, but that doesn't work in my case.

3
  • Please provide your code Commented Nov 21, 2017 at 8:14
  • 2
    Check the network panel in chrome's developer tools. Your app is probably requesting a JS file on a relative path, which causes this error (expecting a JS file but loading an HTML file - a 404, for instance - will trigger this error). Commented Nov 21, 2017 at 8:16
  • Thank you, you were right. I indeed made a typo and my JS file has been requested by relative path and that caused my problem Commented Nov 21, 2017 at 8:29

2 Answers 2

4

to solve this problem in my case was to change the script in the index.html

from = <script src="bundle.js"></script>

To = <script src="/bundle.js"></script>

just by adding the '/' before the bundle.js

i hope that solves your problem too. you mind need to add the '/' for every script in your index.html file

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

Comments

0

For my version of react-scripts (^5.0.0) there is no more <script src= in the index.html.

In this case the solution was to update the homepage property in the package.json to point to the full deployed url of the app.

Before:

homepage: "."

After:

homepage: "https://www.coolwebsite.com"

Comments

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.