Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
Script error while serving react app from a subdirectory

I'm trying to serve a react application (created using craco) from a subdirectory (https://my-domain/app). Following the steps of this guide, and modifying nginx config's location to /app, I do get the static content, but some chunks generate the following error in Chrome:

Uncaught SyntaxError: Unexpected token '<' ... main.b5d3f270.chunk.js:1

Digging in, I noticed nginx returns an html page instead of pure javascript code, and the offending < is (probably) the beginning of <!doctype html>:

<!doctype html>
<html lang="en">

<head>
   ...
</head>
<body><noscript>You need to enable JavaScript to run this app.</noscript>
    ...
    <script>
        !function...
    </script
</body>

This only happens when I serve the app from the sub-folder.

Any idea what the problem is?

A similar, unanswered question can be found here.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Indeed, the problem was with nginx configuration, not with React. I was missing a directive to tell nginx to ignore the 'app' part of the URL, and to load files from a different directory. Doing the following solved the problem:

location /app {
    alias /usr/share/nginx/html;
    try_files $uri $uri/ /app/index.html =404;           
}

Similar solutions are discussed here and here.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!