Thursday, 8 December 2022

React SyntaxError: Unexpected token '<'

When I visit all routes of initial nesting(such as / or /company or /users and so) all is good. But when I visit pages with more route nesting by entering it's url it gives me white screen and error logs in a console.

[Error] SyntaxError: Unexpected token '<'
    (anonymous function) (bundle.js:1)
[Error] SyntaxError: Unexpected token '<'
    (anonymous function) (vendors~main.chunk.js:1)
[Error] SyntaxError: Unexpected token '<'
    (anonymous function) (main.chunk.js:1)

But one strange thing for me - I can visit routes of any nesting by react-router-dom's push like router.push("/company/events"), but when I refresh the page on 2+ nesting it gives me white screen and previously attached error.

And it turns out that these bundle, vendors and main.chunk js files are just containing html code that starts from <!DOCTYPE html>(not js as should) - so of course there should be such error.

I thought it was Nginx configuration at first but location / satisfies any route nesting whether it / or /company/events.

Get this refreshing 2+ nesting routes such as /company/events or /payment/tariffs: enter image description here

And this one, refreshing 0-1 nesting such as / or /company or /payment : enter image description here



from React SyntaxError: Unexpected token '<'

No comments:

Post a Comment