Serverless-express: Cannot find module 'aws-serverless-express'

Created on 19 Sep 2019  路  1Comment  路  Source: vendia/serverless-express

I tried to turn my express application to be serverless,
I followed the documents and seems everything alright on my dist I have lambda.js and server.js
on running locally by
AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:-us-east-1} sam local start-api
will get
`npm run start

[email protected] start /Users/amir/source/oc-source/krs-oc-backend
npm run build && AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:-us-east-1} sam local start-api

[email protected] build /Users/amir/source/oc-source/krs-oc-backend

rimraf dist &&./node_modules/.bin/tsc -p .

2019-09-19 09:43:49 Mounting RequestHandler at http://127.0.0.1:3000/{command+} [GET, DELETE, PUT, POST, HEAD, OPTIONS, PATCH]
2019-09-19 09:43:49 You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be
reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template

  • Tip: There are .env files present. Do "pip install python-dotenv" to use them.
    2019-09-19 09:43:49 * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
    2019-09-19 09:43:53 Invoking lambda.handler (nodejs8.10)
    2019-09-19 09:43:53 Found credentials in shared credentials file: ~/.aws/credentials

Fetching lambci/lambda:nodejs8.10 Docker container image......
2019-09-19 09:43:54 Mounting /Users/amir/source/oc-source/krs-oc-backend/dist as /var/task:ro,delegated inside runtime container
START RequestId: 9a4873c8-4000-137c-950f-52c3166327df Version: $LATEST
Unable to import module 'lambda': Error
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object. (/var/task/lambda.js:6:50)
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)
END RequestId: 9a4873c8-4000-137c-950f-52c3166327df
REPORT RequestId: 9a4873c8-4000-137c-950f-52c3166327df Duration: 13.21 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 30 MB
2019-09-19 09:43:56 Invalid API Gateway Response Keys: {'stackTrace', 'errorMessage', 'errorType'} in {'errorMessage': "Cannot find module 'aws-serverless-express'", 'errorType':
'Error', 'stackTrace': ['Function.Module._load (module.js:474:25)', 'Module.require (module.js:596:17)', 'require (internal/module.js:11:18)', 'Object. (/var/task/lam
bda.js:6:50)', 'Module._compile (module.js:652:30)', 'Object.Module._extensions..js (module.js:663:10)', 'Module.load (module.js:565:32)', 'tryModuleLoad (module.js:505:12)', 'Fu
nction.Module._load (module.js:497:3)']}
2019-09-19 09:43:56 Function returned an invalid response (must include one of: body, headers, multiValueHeaders or statusCode in the response object). Response received: {"error
Message":"Cannot find module 'aws-serverless-express'","errorType":"Error","stackTrace":["Function.Module._load (module.js:474:25)","Module.require (module.js:596:17)","require (
internal/module.js:11:18)","Object. (/var/task/lambda.js:6:50)","Module._compile (module.js:652:30)","Object.Module._extensions..js (module.js:663:10)","Module.load (m
odule.js:565:32)","tryModuleLoad (module.js:505:12)","Function.Module._load (module.js:497:3)"]}
2019-09-19 09:43:56 127.0.0.1 - - [19/Sep/2019 09:43:56] "GET /api/v2/customers HTTP/1.1" 502 -
^C^C
Aborted!
[1] 42435 terminated npm run start`

Most helpful comment

found the issue and I posted here for future reference

this was my template.yml file

Resources: RequestHandler: Type: AWS::Serverless::Function Properties: CodeUri: ./dist Handler:/lambda.handler

and solved after changing it to
Resources: RequestHandler: Type: AWS::Serverless::Function Properties: CodeUri: . Handler: dist/lambda.handler

>All comments

found the issue and I posted here for future reference

this was my template.yml file

Resources: RequestHandler: Type: AWS::Serverless::Function Properties: CodeUri: ./dist Handler:/lambda.handler

and solved after changing it to
Resources: RequestHandler: Type: AWS::Serverless::Function Properties: CodeUri: . Handler: dist/lambda.handler

Was this page helpful?
0 / 5 - 0 ratings

Related issues

donny08 picture donny08  路  8Comments

Vadorequest picture Vadorequest  路  3Comments

bansalrachita picture bansalrachita  路  4Comments

goldenbearkin picture goldenbearkin  路  9Comments

theweaklink picture theweaklink  路  3Comments