Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

211
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda