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

312
Vistas
Vuejs require("axios") in .js file, require is not defined

I'm using vuejs and I'm trying to make a GET request to my API. I'm using axios, but I cannot import it, if I use require to import axios i get this error: Uncaught ReferenceError: require is not defined.

This is my vuetest.js file:

const axios = require("axios");

new Vue({
  el: "#rentalsVue",
  data() {
    return {
      info: null,
    };
  },
  mounted() {
    axios.get("/getRentals").then((response) => (this.info = response));
  },
});

This is the html:

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>

<body>
    <div id="rentalsVue">
        {{ info }}
    </div>


    <script src="vuetest.js"></script>
</body>

</html>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This happens because require() doesn't exist on browser/client-side JavaScript.

You need to import Axios using the <script> tag and then you will be able to use it.

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