React App not loading, showing "Uncaught SyntaxError: Unexpected token '<'" in console, but works in Private Window

Viewed 65

I have browsed many possible solutions to this error with no success. I understand the fundamental issue is that the request to /static/js/main.[hash].js is expecting JS, and instead is returning HTML. I can not, however, understand why the application runs fine while using a Private window, and also will work ONE time after clearing cache and hard reload. In addition to the error message, we get a white screen and the app does not load.

Looking at the Network tab in the browser, I compared the request when working and when not working. I noticed that when working, i.e. in private window, it seems as though the HTML is fetched using a different endpoint, /null. The response is the same HTML that causes the error (the app HTML), but for some reason it works here.

It seems as though the error could be fixed if I could define the request to accept HTML or JSX, but I don't know where to find where this request is called as it seems as though this is all handled by Webpack.

One thing to note, is that when running yarn build and serving the build locally, we still get the error message, but the app does load (no white screen). In the local build HTML, we find a script tag like this:

<script src="undefined"></script>

While the production (breaking) build gives us this:

<script type="text/javascript" src="/static/js/main.ff34f559.js"></script>

edit: The project was created using CRA then freshly ejected

Any help is greatly appreciated!

0 Answers
Related