serverless: V4: dev mode throws error when function invoked
Issue description
After running serverless dev on a simple service, running serverless invoke on a function in the service or invoking it by making an HTTP request causes dev mode to fail with an error. Full serverless support output in Context below.
Error received:
Error: Cannot find module '/opt/sls-sdk-node'
Require stack:
- internal/preload
at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
at Module._load (node:internal/modules/cjs/loader:984:27)
at internalRequire (node:internal/modules/cjs/loader:174:19)
at Module._preloadModules (node:internal/modules/cjs/loader:1574:5)
at loadPreloadModules (node:internal/process/pre_execution:723:5)
at setupUserModules (node:internal/process/pre_execution:203:5)
at prepareExecution (node:internal/process/pre_execution:159:5)
at prepareMainThreadExecution (node:internal/process/pre_execution:54:10)
at node:internal/main/run_main_module:11:19 {
code: 'MODULE_NOT_FOUND',
requireStack: [ 'internal/preload' ]
}
Node.js v20.12.2
✖ ENOENT: no such file or directory, open '/tmp/sls_3329370.json'
Error: ENOENT: no such file or directory, open '/tmp/sls_3329370.json'
Context
Service Overview
- Serverless Framework Version: 4.0.26
- Service Config File: serverless.yml
- Service Name: test-http-api2
- Service App: test-http-api
- Service Runtime: nodejs20.x
- Service Stage: dev
- Service Region: us-east-1
- Command: invoke --function hello2
Service Path
/home/garethm/Projects/testing/test-http-api
Service Config
org: xxx
app: test-http-api
service: test-http-api2
provider:
timeout: 20
name: aws
stage: dev
runtime: nodejs20.x
deploymentBucket:
name: xxxxxxxx
functions:
hello2:
handler: handler.hello
events:
- http:
method: get
path: /
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 20 (9 by maintainers)
Thank you @austencollins - that works as advertised.
Dev mode is super useful!
The actual stack trace is a little different. Maybe this will help:
Hello. I am getting the same error too. its pretty frustating. (Also using ts) Serverless ϟ Support
This generates a report from your last Serverless Framework command (including any errors) to use for Github Issues, debugging w/ AI, or creating a support ticket w/ Serverless Inc.
Summary Report -----------------
Service Overview
Service Overview
Service Config
Service Overview
Command
dev --config src/mainThreads/serverless.yml,–stage dev
Service Config
Same here
i am getting the exact same error