Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda module initialization error

I have recently started Lambda function development on AWS. When try to import a JavaScript file I am getting the following error,

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)

In root level I have the index.js file and claim_type.js file inside the model directory.

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;

What is the correct way to import the claim_type.js?

like image 224
Lakmal Avatar asked Oct 29 '22 03:10

Lakmal


1 Answers

const Sequelize = require('sequelize');

const ClaimType = sequelize.define('claimtype', {

your const is Camelcase, but the second line is lowercase!

like image 86
UXDart Avatar answered Nov 11 '22 18:11

UXDart