This repository was archived by the owner on Jan 28, 2025. It is now read-only.
Custom lambda handler can't be found - cannot resolve files if next.config is in a different folder to serverless #84
Open
Description
Hi
Using node10.x
. Here is my serverless.yml
service: project
plugins:
- serverless-nextjs-plugin
- serverless-domain-manager
- serverless-offline
custom:
# Our stage is based on what is passed in when running serverless
# commands. Or fallsback to what we have set in the provider section.
stage: ${self:provider.stage}
prefixes:
RESOURCES_PREFIX: ${self:service.name}-${self:provider.stage}
serverless-nextjs:
nextConfigDir: ./client/
staticDir: ./client/static
customHandler: ./lambda-handler.js
pageConfig:
categories:
events:
- http:
path: categories/
method: GET
- http:
path: categories/{slug}
method: GET
episode:
events:
- http:
path: episode/
method: GET
- http:
path: episode/{slug}
method: GET
customDomain:
domainName: project-name
basePath: ''
stage: ${self:custom.stage}
createRoute53Record: true
provider:
name: aws
runtime: nodejs10.x
memorySize: 512
timeout: 10
stage: ${env:STAGE, 'staging'}
tags:
SERVICE: ${self:custom.prefixes.RESOURCES_PREFIX}
region: ${opt:region, 'us-east-1'}
package:
exclude:
- ./**/*
However, I get an error on AWS:
Endpoint response body before transformations: {"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module '../lambda-handler.js'","trace":["Runtime.ImportModuleError: Error: Cannot find module '../lambda-handler.js'"," at Object.module.exports.load (/var/runtime/UserFunction.js:86:13)"," at Object.<anonymous> (/var/runtime/index.js:23:30)"," at Module._compile (internal/modules/cjs/loader.js:701:30)"," at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)"," at Module.load (internal/modules/cjs/loader.js:600:32)"," at tryModuleLoad (internal/modules/cjs/loader.js:539:12)"," at Function.Module._load (internal/modules/cjs/loader.js:531:3)"," at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)"," at startup (internal/bootstrap/node.js:283:19)"," at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)"]}
Mon May 27 21:13:18 UTC 2019 : Lambda execution failed with status 200 due to customer function error: Error: Cannot find module '../lambda-handler.js'. Lambda request id: 66fc2ce2-e479-4ea7-b12f-4c22fb94260c
Mon May 27 21:13:18 UTC 2019 : Method completed with status: 502
The crazy thing is that this works perfectly when I deploy it locally using serverless-offline. It also builds perfectly. I have been forced to comment out the custom lambda.
Any ideas?