简体   繁体   English

未定义使用npm安装axios

[英]Installing axios using npm is undefined

I am new to Axios and I am dealing with my first issue! 我是Axios的新手,正在处理我的第一个问题! 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? 另外,我收到一条ENOENT错误:没有这样的文件或目录,请打开/path/../../../有人可以解释原因吗?

Thank you! 谢谢!

UPDATED : 更新时间

I no longer get the ENOENT error. 我不再收到ENOENT错误。

THE FIX : 解决方法

Was to change the name directory to something else rather than axios to axiosapi or anything else! 是将名称目录更改为其他名称,而不是将axios更改为axiosapi或其他任何名称!

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 未捕获的ReferenceError:在axioss.js:1中未定义require

If you are installing globally use npm install -g axios. 如果要全局安装,请使用npm install -g axios。

Otherwise you need to create a project in your current directory: npm init -y 否则,您需要在当前目录中创建一个项目: npm init -y

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM