0
我最近在AWS上開始了Lambda函數開發。當嘗試導入JavaScript文件,我收到以下錯誤,AWS Lambda模塊初始化錯誤
module initialization error: ReferenceError
at Object.<anonymous> (/var/task/model/claim_type.js:3:29)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/var/task/index.js:2:19)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
在根級別我有index.js文件和claim_type.js文件模型目錄中。
index.js
const Sequelize = require('sequelize');
const ClaimType = require('./model/claim_type.js');
exports.handler = function (event, context, callback) {
//function content
}
claim_type.js
const Sequelize = require('sequelize');
const ClaimType = sequelize.define('claimtype', {
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey: true
},
name: {
type: Sequelize.STRING
}
}, {
timestamps: false
});
module.exports = ClaimType;
什麼是導入claim_type.js正確的方法是什麼?
它看起來像沒有找到sequelize。您是否將node_modules目錄與自己的源一起部署到lamdba? – mtkopone
是的,我使用命令* zip -r Lambda-Deployment.zip * -x * .zip * .json * .log *來創建zip文件。我認爲這與sequelize沒有關係,因爲直到我將* ClaimType *移動到單獨的文件中,它才能正常工作。 – Lakmal