gpt4 book ai didi

javascript - 即使安装了 Node,也无法在 Node 中加载 Axios

转载 作者:行者123 更新时间:2023-12-01 03:07:23 27 4
gpt4 key购买 nike

我有一个 Jasmine 测试,其中包含一些 HTTP 请求。我正在使用 Axios 进行基于 Promise 的 HTTP 访问,但由于某种原因,我得到了 axios is not Defined。我已经运行了 npm install axios --save

var request = require('axios');
var constants = require('../../lib/constants.js');

describe('Signing into the application', function () {
it('returns 200 OK', function () {
axios.get(constants.Endpoint)
.then(function (response) {
console.log(JSON.stringify(response));
})
.catch(function (error) {
console.log(JSON.stringify(error));
});
});
});

这是输出:

Failures:

1) Signing into the application returns 200 OK
Message:
ReferenceError: axios is not defined
Stacktrace:
ReferenceError: axios is not defined
at jasmine.Spec.<anonymous> (C:\Users\la\Documents\tests\spec\integration\sign-in\sign-in-spec.js:6:9)

这是package.json:

{
"name": "actual-tests",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jasmine-node spec"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.16.2",
"jasmine-node": "^1.14.5"
}
}

这是怎么回事?

最佳答案

您已定义:

var request = require('axios');

并尝试调用:

axios.get ...

将其更改为:

var axios = require('axios');

关于javascript - 即使安装了 Node,也无法在 Node 中加载 Axios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46092696/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com