1

When I deploy my server less function locally it works fine.but it docent when deploy it to aws lambda.I have included web pack also.Nothing wrong in offline run

Syntax error in module 'handler': SyntaxError
(function (exports, require, module, __filename, __dirname) { import mongoose from 'mongoose';
                                                              ^^^^^^
1
  • 1
    are you using TypeScript? Also can you please share the screenshot where you defineds 'index.handler' in Lambda Commented Sep 21, 2017 at 13:38

2 Answers 2

1

Lambda runs on either Node v4.3 or v6.10. Both versions don't support ES6 modules.

You have to configure your transpiler to transpile to ES5.

For local development, I would suggest you use the same Node version that you use in Lambda so you don't have these "but it works on my local!" moments.

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

Comments

1

Something else it could be. I was getting this issue a few versions of Serverless back when deploying functions individually.

The rub was if you deployed the function individually web pack didn't refactor the es6 down.

So if you find you deploy and its ok then you deploy a function by itself and it gets this error then update serverless and all your plugins and this will go away. (from memory I got past this at about v1.19.0

1 Comment

it was actually runtime being set to nodejs6.10 instead of nodejs8.10, but that put me on the path to solution. thanks

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.