Javascript 无服务器(节点aws)";TypeError"&引用;errorMessage";:&引用;回调不是一个函数";

Javascript 无服务器(节点aws)";TypeError"&引用;errorMessage";:&引用;回调不是一个函数";,javascript,node.js,serverless-framework,aws-serverless,Javascript,Node.js,Serverless Framework,Aws Serverless,在我的handler.js上 'use strict'; var lalamove = require('./lalamove/index.js'); module.exports.getEstimate = (event, context, callback) => { lalamove.getQuotation("hi"); }; 我一直在lalamove/index.js 'use strict'; module.exports = { getQuotation:

在我的
handler.js上

'use strict';
var lalamove = require('./lalamove/index.js');

module.exports.getEstimate = (event, context, callback) => {
  lalamove.getQuotation("hi");
};
我一直在
lalamove/index.js

'use strict';

module.exports = {
    getQuotation: function(event,context,callback){
        const response = {
            statusCode: 200,
            body: JSON.stringify({ message: event })
          }
        console.log('response', response);
        callback(null,response.body);
    }
}
它会记录在控制台日志中。它在控制台中工作,但无法返回。当我检查日志时:

错误调用错误{“errorType”:“TypeError”,“errorMessage”:“回调不是函数”,“堆栈”:[“TypeError:回调不是函数”,“at Object.getQuotence(/var/task/lalamove/index.js:10:9)”,“at Runtime.module.exports.getEstimate[as handler](/var/task/handler.js:14:12)”,“at Runtime.handleOnce”(/var/runtime/runtime.js:63:25)“,“在进程中._tickCallback(internal/process/next_tick.js:68:7)]”

我尝试删除
上下文
,但它仍然是一样的,我尝试使用
返回
而不是
回调
,但它不起作用,我仍然得到:

{"message": "Internal server error"}
而不是

{ statusCode: 200, body: '{"message":"hi"}' }

为了得到响应,您必须对调用方函数实现回调函数,如下所示

'use strict';
var lalamove = require('./lalamove/index.js');

module.exports.getEstimate = (event, context, callback) => {
  lalamove.getQuotation("hi", context, function(response) {
       console.log(response)//it will print return value
   });
};

为了得到响应,您必须对调用方函数实现回调函数,如下所示

'use strict';
var lalamove = require('./lalamove/index.js');

module.exports.getEstimate = (event, context, callback) => {
  lalamove.getQuotation("hi", context, function(response) {
       console.log(response)//it will print return value
   });
};

遗憾的是,它无法工作。它将在控制台中打印,但不能作为函数的返回。请同时传递第二个参数。
lalamove.getquote(“hi”,“context”,“function(response)”{
抱歉,我已复制粘贴了您的答案,但它返回
{“message”:“内部服务器错误”}
请再次检查。您遗漏了一些内容。它对我有效。遗憾的是,它不起作用。它将在控制台中打印,但不会作为函数返回。请传递第二个参数。
lalamove.getquote(“hi”,“context”,“function(response)”{
抱歉,我复制粘贴了您的答案,但它返回
{“message”:“内部服务器错误”}
请再次检查。您遗漏了一些内容。它对我有效。我确实不确定,但我曾经遇到过类似的问题。请尝试传递响应,而不是中的response.bodycallback@SiddharthYadav已经试过了,但不起作用:(我真的不确定,但我曾经遇到过类似的问题。请尝试传递响应,而不是中的response.bodycallback@SiddharthYadav已经试过了,但不起作用:(