Cannot find module 'app' when using "hello world typescript" example
- Dominant language
- Python
- Stars
- 6.7k
- Forks
- 1.2k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 52
Description
Hello 👋
I'm setting up AWS SAM locally on Windows and I've stumbled upon a problem with running a lambda locally. I've used the "Hello World TypeScript" as an example and haven't changed almost anything and I'm receiving the following error:
```
[ERROR] (rapid) Invoke DONE failed: Sandbox.Failure
{"errorType": "Runtime.ImportModuleError", "errorMessage": "Error: Cannot find module 'app'\nRequire stack:\n- /var/runtime/index.mjs", "trace": ["Runtime.ImportModuleError: Error: Cannot find module 'app'", "Require stack:", "- /var/runtime/index.mjs", " at _loadUserApp (file:///var/runtime/index.mjs:1087:17)", " at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)", " at async start (file:///var/runtime/index.mjs:1282:23)", " at async file:///var/runtime/index.mjs:1288:1"]}
```
Full debug log:
```
PS D:\Projects\testApp\server> sam local invoke HelloWorldFunction --debug
2024-07-22 01:21:14,070 | Config file location: D:\Projects\testApp\server\samconfig.toml
2024-07-22 01:21:14,072 | Loading configuration values from [default.['local', 'invoke'].parameters]
(env.command_name.section) in config file at 'D:\Projects\testApp\server\samconfig.toml'...
2024-07-22 01:21:14,073 | Configuration values successfully loaded.
2024-07-22 01:21:14,073 | Configuration values are: {'stack_name': 'testApp-server'}
2024-07-22 01:21:14,077 | Using SAM Template at D:\Projects\testApp\server\.aws-sam\build\template.yaml
2024-07-22 01:21:14,088 | Using config file: samconfig.toml, config environment: default
2024-07-22 01:21:14,089 | Expand command line arguments to:
2024-07-22 01:21:14,089 | --template_file=D:\Projects\testApp\server\.aws-sam\build\template.yaml
--function_logical_id=HelloWorldFunction --no_event --layer_cache_basedir=C:\xx\xx\AppData\Roaming\AWS
SAM\layers-pkg --container_host=localhost --container_host_interface=127.0.0.1
2024-07-22 01:21:14,090 | local invoke command is called
2024-07-22 01:21:14,158 | No current session found, using default AWS::AccountId
2024-07-22 01:21:14,162 | No Parameters detected in the template
2024-07-22 01:21:14,193 | Sam customer defined id is more priority than other IDs. Customer defined id for
resource HelloWorldFunction is HelloWorldFunction
2024-07-22 01:21:14,194 | Sam customer defined id is more priority than other IDs. Customer defined id for
resource TestFunction is TestFunction
2024-07-22 01:21:14,195 | Sam customer defined id is more priority than other IDs. Customer defined id for
resource TestFunctionJS is TestFunctionJS
2024-07-22 01:21:14,196 | There is no customer defined id or cdk path defined for resource
ServerlessRestApi, so we will use the resource logical id as the resource id
2024-07-22 01:21:14,197 | 0 stacks found in the template
2024-07-22 01:21:14,197 | No Parameters detected in the template
2024-07-22 01:21:14,207 | Sam customer defined id is more priority than other IDs. Customer defined id for
resource HelloWorldFunction is HelloWorldFunction
2024-07-22 01:21:14,208 | Sam customer defined id is more priority than other IDs. Customer defined id for
resource TestFunction is TestFunction
2024-07-22 01:21:14,208 | Sam customer defined id is more priority than other IDs. Customer defined id for
resource TestFunctionJS is TestFunctionJS
2024-07-22 01:21:14,209 | There is no customer defined id or cdk path defined for resource
ServerlessRestApi, so we will use the resource logical id as the resource id
2024-07-22 01:21:14,210 | 4 resources found in the stack
2024-07-22 01:21:14,210 | Found Serverless function with name='HelloWorldFunction' and
CodeUri='HelloWorldFunction'
2024-07-22 01:21:14,211 | --base-dir is not presented, adjusting uri HelloWorldFunction relative to
D:\Projects\testApp\server\.aws-sam\build\template.yaml
2024-07-22 01:21:14,212 | Found Serverless function with name='TestFunction' and CodeUri='TestFunction'
2024-07-22 01:21:14,212 | --base-dir is not presented, adjusting uri TestFunction relative to
D:\Projects\testApp\server\.aws-sam\build\template.yaml
2024-07-22 01:21:14,213 | Found Serverless function with name='TestFunctionJS' and CodeUri='TestFunctionJS'
2024-07-22 01:21:14,213 | --base-dir is not presented, adjusting uri TestFunctionJS relative to
D:\Projects\testApp\server\.aws-sam\build\template.yaml
2024-07-22 01:21:14,218 | Found one Lambda function with name 'HelloWorldFunction'
2024-07-22 01:21:14,218 | Invoking app.lambdaHandler (nodejs20.x)
2024-07-22 01:21:14,219 | Loading AWS credentials from session with profile 'None'
2024-07-22 01:21:14,225 | Resolving code path. Cwd=D:\Projects\testApp\server\.aws-sam\build,
CodeUri=D:\Projects\testApp\server\.aws-sam\build\HelloWorldFunction
2024-07-22 01:21:14,226 | Resolved absolute path to code is
D:\Projects\testApp\server\.aws-sam\build\HelloWorldFunction
2024-07-22 01:21:14,227 | Resolving code path. Cwd=D:\Projects\testApp\server\.aws-sam\build,
CodeUri=D:\Projects\testApp\server\.aws-sam\build\HelloWorldFunction
2024-07-22 01:21:14,227 | Resolved real code path to
D:\Projects\testApp\server\.aws-sam\build\HelloWorldFunction
2024-07-22 01:21:14,228 | Code D:\Projects\testApp\server\.aws-sam\build\HelloWorldFunction is not a
zip/jar file
2024-07-22 01:21:16,928 | Local image is up-to-date
2024-07-22 01:21:16,931 | Checking free port on 127.0.0.1:7773
2024-07-22 01:21:16,933 | Using local image: public.ecr.aws/lambda/nodejs:20-rapid-x86_64.
2024-07-22 01:21:16,934 | Mounting D:\Projects\testApp\server\.aws-sam\build\HelloWorldFunction as
/var/task:ro,delegated, inside runtime container
2024-07-22 01:21:17,224 | Starting a timer for 3 seconds for function 'HelloWorldFunction'
2024-07-22 01:21:17,226 | Getting lock for the key localhost-7773
2024-07-22 01:21:17,226 | Waiting to retrieve the lock (localhost-7773) to start invocation
START RequestId: d337cb92-eafa-4ddc-ac0c-3d5dfbb7ce27 Version: $LATEST
2024-07-21T23:21:18.277Z undefined ERROR Uncaught Exception {"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'app'\nRequire stack:\n- /var/runtime/index.mjs","stack":["Runtime.ImportModuleError: Error: Cannot find module 'app'","Require stack:","- /var/runtime/index.mjs"," at _loadUserApp (file:///var/runtime/index.mjs:1087:17)"," at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)"," at async start (file:///var/runtime/index.mjs:1282:23)"," at async file:///var/runtime/index.mjs:1288:1"]}
21 Jul 2024 23:21:18,286 [ERROR] (rapid) Init failed error=Runtime exited with error: exit status 129 InvokeID=
21 Jul 2024 23:21:18,286 [ERROR] (rapid) Invoke failed error=Runtime exited with error: exit status 129 InvokeID=a4dea20a-1ea1-4ead-971e-4e49bf151570
21 Jul 2024 23:21:18,286 [ERROR] (rapid) Invoke DONE failed: Sandbox.Failure
{"errorType": "Runtime.ImportModuleError", "errorMessage": "Error: Cannot find module 'app'\nRequire stack:\n- /var/runtime/index.mjs", "trace": ["Runtime.ImportModuleError: Error: Cannot find module 'app'", "Require stack:", "- /var/runtime/index.mjs", " at _loadUserApp (file:///var/runtime/index.mjs:1087:17)", " at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)", " at async start (file:///var/runtime/index.mjs:1282:23)", " at async file:///var/runtime/index.mjs:1288:1"]}
```
I have ran the `sam build` function before running the function, the build was successfully created.
Would appreciate guidance as I did not have time to fully investigate this just yet, didn't bother especially that this might be a known problem. The path to the "module" which is `'app'` does not seem correct though 🤔
Contributor guide
Assessment
This issue has not been assessed yet.