Code runs without errors when I require
compared to when I import
, then I receive an error:
app.js:
// require("@babel/polyfill");
// require("@babel/core");
import babel from '@babel/core';
import babelpoly from '@babel/polyfill';
import axios from 'axios';
const BASE_URL = 'https://jsonplaceholder.typicode.com';
const getTodos = async () => {
try {
const res = await axios.get(`${BASE_URL}/todos`);
const todos = res.data;
console.log(`GET: Here's the list of todos`, todos);
return todos;
} catch (e) {
console.error(e);
}
};
Based on what I understand, require
and import
have the same functionality but they have performance trade offs. I must be wrong, otherwise it would've worked both ways