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

337
Visualizações
while adding the dotenv file i got the error Error : [TypeError: Network request failed]
bable.config.js File

plugins: [
    ["module:react-native-dotenv", {
      "envName": "APP_ENV",
      "moduleName": "@env",
      "path": ".env",
      "blocklist": null,
      "allowlist": null,
      "blacklist": null, // DEPRECATED
      "whitelist": null, // DEPRECATED
      "safe": false,
      "allowUndefined": true,
      "verbose": false
    }]
  ]

.env File code

API_LOGIN=https://example.in/login

login.js

import { API_LOGIN } from '@env';

const url = API_LOGIN;
let email = this.state.gmail;
let password = this.state.password;
fetch(url, {
  method: 'POST',
  body: JSON.stringify({
    email: email,
    password: password,
  }),
  headers: new Headers({
    'Content-Type': 'application/json',
  }),
})
  .then((res) => res.json())
  .catch((error) => console.error('Error : ', error))

  .then((response) => {
    if (response.access_token != undefined) {
      this.setState({
        accessToken: response.access_token,
      });

      if (this.state.accessToken != '') {
        this.props.navigation.navigate('VolunteerHome', {
          AccessToken: this.state.accessToken,
        });
      }
    } else {
      alert('Unauthorised User');
    }
  });

In the above code, I have installed dotenv. Then I have added the plugin code in the bable.config.js file. then I have create .env file in root directory and created the environmental variable API_Login=example.in/login then import the package in login.js file and use that variable. But I got a network error in my code if I simply add the API URL in the login file then my code run properly. please help me to solve this problem

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

0

If you try to use it as a string ?

const url = `${API_LOGIN}`;

You can also import it like that : process.env.API_LOGIN
You also need require('dotenv').config()
More info 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