Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

297
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!