0
votes

I have a working yarn react project on a local machine.

yarn start

Works, yields a website that renders on the local host.

I have a server that was running the same project. However, I stopped the running website, and restarted with the following commands:

yarn install 
yarn run build
yarn run prod

And I get the following error when accessing the website through chrome (on the production server):

Ucaught SyntaxError: Unexpected token <

What I am trying to do is diagnose where the problems could be arising. To summarize:

1) the project runs on the local machine (mac osx) with yarn start

2) I place the project on the linux box, install, build and run and everything seems to be sending to chrome; however, chrome yields this error

I am not sure where the problem could be. Localizing it to a set of possible problems would, I think, make it easy to solve (or ask better questions).

1

1 Answers

1
votes

That error typically happens when you are getting a HTML page for a <script> tag src's address.

Open the URLs of the scripts each on a different tab (or check the network tab of the developer tools), those URLs are probably returning a 404 (or some other error code) and a HTML error page.

So your code tries to parse those HTML error pages as JavaScript code, thus yielding that error.

It gets Uncaught SyntaxError: Unexpected token < because it tries to parse the HTML content (e.g. <html> ...) as JavaScript code.

For a demo, run the snippet below and see the error at the console.

<script type=text/javascript src=https://stackoverflow.com></script>
Check the console: "Uncaught SyntaxError: Unexpected token <"