【发布时间】:2020-07-14 13:01:01
【问题描述】:
我有一个简单的函数,它使用 axios 进行 API 调用。它被多次调用,几次之后我都得到了同样的错误:
Trace: TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type Function. Received type object
at checkListener (events.js:77:11)
at TLSSocket.once (events.js:326:3)
at Object.connect (_tls_wrap.js:1425:13)
at Agent.createConnection (https.js:125:22)
at Agent.createSocket (_http_agent.js:242:26)
at Agent.addRequest (_http_agent.js:201:10)
at new ClientRequest (_http_client.js:276:16)
at Object.request (https.js:309:10)
at RedirectableRequest._performRequest (webpack:///./node_modules/follow-redirects/index.js?:169:24)
at new RedirectableRequest (webpack:///./node_modules/follow-redirects/index.js?:66:8) {
code: 'ERR_INVALID_ARG_TYPE'
}
我在我的应用程序中使用 Vue 作为前端,但是这个函数是从 NodeJS 后端调用的。
Axios 实例:
this.axios = axios.create({
withCredentials: true,
responseType: 'json'
});
axios 调用:
await this.axios({
url: this.url,
method: 'POST',
headers: this.headers,
responseType: 'json',
withCredentials: true,
params: {
input: 'test',
method: method
},
data: callData
});
谢谢。
【问题讨论】:
-
你是如何配置axios的?
-
它是否安装在您的后端并且需要正确?
-
@Daniel_Knights 我已经用它更新了这个问题。另外 - 我试过删除 node_modules 并运行 npm install,结果是一样的。
-
您是否安装过 Node 并需要它?
-
@Daniel_Knights 是的,整个项目都使用相同的 node_modules。在 Node 中,我使用了
import axios from 'axios';来导入它。
标签: javascript node.js axios