未定义使用npm安装axios [英] Installing axios using npm is undefined
问题描述
我是Axios的新手,正在处理我的第一个问题!我用
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
另外,我收到一条ENOENT错误:没有这样的文件或目录,请打开/path/../../../ 有人可以解释原因吗?
Also, I get an ENOENT error: no such file or directory, open /path/../../../ Can someone explain the reason?
谢谢!
已更新:
我不再收到ENOENT错误.
I no longer get the ENOENT error.
修复:
是要将名称目录更改为其他名称,而不是将axios更改为axiosapi或其他任何内容!
Was to change the name directory to something else rather than axios to axiosapi or anything else!
新问题:
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) )
未捕获的ReferenceError:未定义require 在axioss.js:1
Uncaught ReferenceError: require is not defined at axioss.js:1
推荐答案
如果要全局安装,请使用npm install -g axios.
If you are installing globally use npm install -g axios.
否则,您需要在当前目录中创建一个项目:npm init -y
Otherwise you need to create a project in your current directory: npm init -y
这篇关于未定义使用npm安装axios的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!