Installing axios using npm is undefined

怎甘沉沦 提交于 2019-12-13 03:25:01

问题


I am new to Axios and I am dealing with my first issue! I installed it with

npm install axios

and I get this error! enter image description here

Also, I get an ENOENT error: no such file or directory, open /path/../../../ Can someone explain the reason?

Thank you!

UPDATED:

I no longer get the ENOENT error.

THE FIX:

Was to change the name directory to something else rather than axios to axiosapi or anything else!

NEW ISSUE :

const axios = require('axios');

const api_url = 'https://opentdb.com/api.php?amount=1';
console.log(api_url);


axios.get(api_url)
.then(
    response => {
        if(!response.ok) {
        throw Error(response);
        }
        return response;
    }
)
.then( response => console.log(response) )

.catch( err =>  console.log(err) )

Uncaught ReferenceError: require is not defined at axioss.js:1


回答1:


If you are installing globally use npm install -g axios.

Otherwise you need to create a project in your current directory: npm init -y



来源:https://stackoverflow.com/questions/52936927/installing-axios-using-npm-is-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!