shashik thiwanka
shashik thiwanka

Reputation: 81

Serverless Unable to import module 'handler' Error

When I'm testing on local machine it's working fine, but after I deploy it to lambda, it's not working anymore. It throws this error:

Unable to import module 'handler': Error

at Module._compile (module.js:652:30)

at Object.Module._extensions..js (module.js:663:10)

at Module.load (module.js:565:32)

at tryModuleLoad (module.js:505:12)

at Function.Module._load (module.js:497:3)

I spent a lot of time trying to solve this issue. Please can someone help me with this issue?

Upvotes: 0

Views: 834

Answers (1)

Yogesh Sinoriya
Yogesh Sinoriya

Reputation: 91

If you have the structure like:

  |--lambda
  |    `----create.js
  |--serverless.yml

Then try this.

In file serverless.yml:

functions:
    create:
        handler: create.handle

In file, lambda/create.js

module.exports.handle = async event => {
    return "something";
};

check my example code at https://github.com/yogesh-sinoriya/serverless-dynamodb-authorizer

Upvotes: 1

Related Questions