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

142
Visualizações
Environmental variable undefined in React APP

I am trying to set the URL of the API at runtime. I followed this tutorial which solves the exact problem I have, but still, the variable is undefined.

I put the file with enviromental variable in script in index.html (EDITED)

<script src="%PUBLIC_URL%/env-config.js"></script>

Inside of which is (after the image starts through Docker) something like this:

window._env_ = {
    API_URL: "my-awesome-url" // filled by bash script defined in ENTRYPOINT
}

But when I want to use it in the React app I get something like cannot read property of undefined API_URL. When I try to access the window object in console, I can see, the _env_ variable is not present in the object. What am I missing?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The script tag is wrong. It is supposed to be like <script src="%PUBLIC_URL%/env-config.js"></script>

Check and try again.

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