我最近在AWS上开始了Lambda功能开发。当我尝试导入JavaScript文件时,我收到以下错误,
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)
在root级别,我在 model 目录中有 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 的正确方法是什么?
答案 0 :(得分:1)
const Sequelize = require('sequelize');
const ClaimType = sequelize.define('claimtype', {
你的const是Camelcase,但第二行是小写的!