Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

534
Vistas
TypeError: axios(...).then is not a function

I am creating a javascript function to use in glideapps, following this process. The function takes in a google maps api url as a string input, and returns the json file as a string output. Using the example from google, I created this test which works fine.

function test(request_url){
  var axios = require('axios');
  var config = {
    method: 'get',
    url: request_url,
    headers: { }
  };

  var final = axios(config)
  .then(function (response) {
    console.log(JSON.stringify(response.data));
  })
  .catch(function (error) {
    console.log(error);
  })
  return final}

When I use the same function in the code for the glideapp function, I get two errors. First, I got the error: Error: Module name "axios" has not been loaded yet for context: _. Use require([]) and addressed it by using var axios = require(['foo'], function (foo) instead.

window.function=function(request_url){ 
  var axios = require(['axios'], function (axios) {
    //axios is now loaded.
  });
  var config = {
    method: 'get',
    url: request_url,
    headers: { }
  };

  var final = axios(config)
  .then(function (response) {
    console.log(JSON.stringify(response.data));
  })
  .catch(function (error) {
    console.log(error);
  })
  return final}

Now I get the error TypeError: axios(...).then is not a function. How do I fix this? Thank you

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Use the axios variable inside the function of require instead of the returning value of require function.

require(['axios'], function (axios) {
    window.function=function(request_url){ 
      var config = {
        method: 'get',
        url: request_url,
        headers: { }
      };

      var final = axios(config)
      .then(function (response) {
        console.log(JSON.stringify(response.data));
      })
      .catch(function (error) {
        console.log(error);
      })
      return final
    }
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda