Leonid Gordun
Leonid Gordun

Reputation: 391

React (router?) Uncaught SyntaxError: Unexpected token <

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.

Upvotes: 1

Views: 1734

Answers (2)

mircealungu
mircealungu

Reputation: 6981

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"

Upvotes: 0

prince kohan matumane
prince kohan matumane

Reputation: 41

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

Upvotes: 4

Related Questions