【问题标题】:Unable to import module 'api/candidate': Error at Function.Module._resolveFilename无法导入模块“api/candidate”:Function.Module._resolveFilename 出错
【发布时间】:2018-08-31 23:17:29
【问题描述】:

我正在使用 nodejs、Dynmodb 和 Serverless 框架中的 Lamda 函数创建无服务器应用程序。我已经创建了 Lamda 函数 从 Dynmodb 表中获取数据,但是当我尝试通过端点获取数据时出现此错误。

Lamda 函数 index.js :

'use strict';
var AWS = require('aws-sdk'),
    documentClient = new AWS.DynamoDB.DocumentClient(); 

exports.list = function(event, context, callback){
    var params = {
        TableName : process.env.TABLE_NAME
    };
    documentClient.scan(params, function(err, data){
        if(err){
            callback(err);
        }else{
            callback(null, data.Items);
        }
    });
}

CloudWatchLog Groups/aws/lambda/my-service-dev-listCandidates 中的错误:

Unable to import module 'api/candidate': Error
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)

在从端点获取数据时,我得到了这个:

{"message": "内部服务器错误"}

【问题讨论】:

    标签: node.js amazon-web-services aws-lambda aws-sdk serverless-framework


    【解决方案1】:

    您可能还有其他错误,但肯定您在 require 中有错误的语法:

    var AWS = require('aws-sdk'),
    

    应该是:

    var AWS = require('aws-sdk');
    

    【讨论】:

    • 更改后,我的 cloudwatch 中仍然出现此错误:模块初始化错误:ReferenceError at Object. (/var/task/index.js:100:17) at Module._compile ( module.js:570:32) 在 Object.Module._extensions..js (module.js:579:10) 在 Module.load (module.js:487:32) 在 tryModuleLoad (module.js:446:12)在 Function.Module._load (module.js:438:3) 在 Module.require (module.js:497:17) 在 require (internal/module.js:20:19)
    • 已解决..实际上,我没有返回任何状态,它给了我一个错误
    猜你喜欢
    • 1970-01-01
    • 2019-02-09
    • 2018-04-26
    • 1970-01-01
    • 2020-01-19
    • 1970-01-01
    • 2021-11-19
    • 2016-05-22
    • 2021-08-28
    相关资源
    最近更新 更多