Node.js 此.app.service(…).create(…)不是函数
我尝试两次发出api请求,第一次成功,但第二次失败,错误如下Node.js 此.app.service(…).create(…)不是函数,node.js,feathersjs,Node.js,Feathersjs,我尝试两次发出api请求,第一次成功,但第二次失败,错误如下 { "name": "GeneralError", "message": "this.app.service(...).create(...) is not a function", "code": 500, "className": "general-error"
{
"name": "GeneralError",
"message": "this.app.service(...).create(...) is not a function",
"code": 500,
"className": "general-error",
"data": {},
"errors": {}
}
result.class.js
/* eslint-disable no-unused-vars */
const errors = require('@feathersjs/errors');
exports.Submission = class Submission {
constructor (options, app) {
this.app = app;
}
async create (data, params) {
if (Array.isArray(data)) {
return Promise.all(data.map(current => this.create(current, params)));
}
let result = await this.app.service('result').create({ //<------------- It works
sectionId: data.sectionId,
})
console.log(result) // <------------------------------------ able to show the value
(data.sub_sections).map(async sub_section =>{
(sub_section.questions).map(async question =>{
let payload = {
answerId: question.questionId
}
await this.app.service('result').create(payload) //<------------- It results in error
})
})
return data;
}
};
/*eslint禁用未使用的变量*/
const errors=require(“@feathersjs/errors”);
exports.Submission=类提交{
构造函数(选项、应用程序){
this.app=app;
}
异步创建(数据、参数){
if(Array.isArray(数据)){
返回Promise.all(data.map(current=>this.create(current,params));
}
让result=等待这个.app.service('result')。创建({//{
让有效载荷={
回答:问题
}
等待此.app.service('result').create(payload)//似乎不是第二次调用this.app.service().create()
导致您看到的错误
我猜当您没有console.log()
语句时,会出现报告的特定错误消息。这是因为缺少分号
let result = await this.app.service('result').create({
sectionId: data.sectionId,
}) // no semi-colon here
(data.sub_sections).map(//..)
如果下一个非空格字符不能解释为当前语句的延续,JavaScript仅将换行符视为分号(即语句的结尾)。但在本例中,它可以被视为对前面wait
表达式结果的调用
请注意,在中间插入console.log()
语句时,您应该会遇到类似的问题:
console.log(...) is not a function
因此,在这种情况下,只需手动添加分号。您可以共享服务代码吗?您在哪里使用提交?console
this.app
并查看您得到了什么??