5

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?

2
  • It looks like sequelize isn't found. Are you deploying the node_modules directory with you own sources to lamdba? Commented Aug 10, 2017 at 11:42
  • yes, I am using the command zip -r Lambda-Deployment.zip * -x *.zip *.json *.log to create the zip file. I think it's not related to the sequelize because it was working fine until I moved the ClaimType to a separate file. Commented Aug 10, 2017 at 12:04

1 Answer 1

2
const Sequelize = require('sequelize');

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

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.