What it means
Lambda runs your function in two phases, and this error belongs entirely to the first one. During init, the runtime loads your handler file and everything it imports, top to bottom, before any event arrives. During invoke, it calls the handler with the event. A module that cannot be resolved fails in init, which means the failure happens before your code has run a single line and before there is an event to fail.
That timing explains the two things people find most confusing about it. The first is that the logs contain none of your own output — not even a log line at the very top of the file, because the file never finished loading. The second is that it fails identically every single time. A bug in your handler might affect one request in a thousand; a missing module affects every invocation on every container, forever, until the package changes.
The Require stack: block is the part worth reading and the part most often skipped. It is the chain of files Node walked to reach the failed require, listed innermost first. When the missing module is one you have never heard of, that chain tells you which of your dependencies wanted it — which is usually a package whose own dependencies did not make it into the bundle, rather than anything you imported yourself.
Almost every instance of this error comes down to a difference between the machine that built the package and the machine that runs it. Case sensitivity differs between macOS and Linux. devDependencies are present locally and pruned in CI. Native bindings are compiled for arm64 on a laptop and loaded on x86_64 in production. The AWS SDK is present in the runtime in one major version and absent in another. In every case the code is correct and the artifact is wrong, which is why the fix is nearly always in the build rather than in the source.
CloudWatch’s Errors metric: The error escaped your handler, so Lambda reports the invocation as failed and CloudWatch’s Errors metric counts it. LogStitch classified the invocation above as uncaught.
What it looks like in CloudWatch
This is the shape the failure arrives in: the lines of one invocation scattered among everything else the log group received at the same moment.
CloudWatch Logs Before
8 raw lines, in the order CloudWatch delivered them.
LogStitch After
The same lines, grouped into the invocation they belong to.
ErrorCold start · 284ms initc8d31f04-72ae-4b19-8f2c-1a4e6b9d0c55
- 06:41:02.118PLAT
INIT_START Runtime Version: nodejs:22.v14 Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:d1e0a1c1f0e0
- 06:41:02.402
Runtime.ImportModuleError: Error: Cannot find module 'lodash'
- 06:41:02.402
Require stack:
- 06:41:02.402
- /var/task/index.js
- 06:41:02.402
- /var/runtime/index.mjs
- 06:41:02.511PLAT
START RequestId: c8d31f04-72ae-4b19-8f2c-1a4e6b9d0c55 Version: $LATEST
- 06:41:02.514PLAT
END RequestId: c8d31f04-72ae-4b19-8f2c-1a4e6b9d0c55
- 06:41:02.514PLAT
REPORT RequestId: c8d31f04-72ae-4b19-8f2c-1a4e6b9d0c55 Duration: 3.42 ms Billed Duration: 4 ms Memory Size: 256 MB Max Memory Used: 68 MB Init Duration: 284.11 ms Status: error Error Type: Runtime.ImportModuleError
The panel on the right is generated by running the excerpt on the left through the same parser that powers the free web stitcher — it is what the tool actually produces for this input, not an illustration of it.
How to confirm it from the logs
Three things identify this precisely. The error appears immediately after INIT_START and before any of your own logging, because it happens during module load. The Require stack: block underneath lists the chain of files that led to the failed require, and its first entry names the file that actually asked for the module. And the REPORT line carries Error Type: Runtime.ImportModuleError on runtimes that write it.
The name in quotes is the module Node could not resolve, not necessarily the one you are missing — a package present in your bundle can still fail if one of its dependencies is absent. Read the Require stack to see which of your files started the chain.
Causes, most likely first
The dependency was never installed into the deployment package
Unzip the deployed artifact and look for the module under node_modules. It is common for a package to be in package.json, present locally, and simply absent from the zip because the build installed with --production and it was listed under devDependencies, or because node_modules was excluded from the upload entirely.
The AWS SDK is assumed to be present but is not, or is the wrong major version
Check which SDK the module name refers to. Node 18 and later ship AWS SDK v3 only — require('aws-sdk'), which is v2, fails on those runtimes and must be bundled explicitly. The v3 packages are scoped, so @aws-sdk/client-s3 and friends are the ones available.
The case of the filename does not match
Compare the exact spelling in the import against the file in the package. macOS and Windows filesystems are case-insensitive; the Lambda execution environment is Linux and is not. require('./Utils') finds utils.js on a laptop and fails in production, and this is the version of the bug that passes every local test.
A native module was built for the wrong platform or architecture
Check whether the missing module has a compiled component, and where it was installed. A dependency with native bindings installed on macOS or on an arm64 machine will not load on an x86_64 Lambda; the resolution failure is often the first symptom.
The handler path in the function configuration does not match the file
Look at whether the module in the message is one of yours rather than a dependency — Cannot find module '/var/task/index' means Lambda could not find the entry file the handler string names. Check the configured handler against the actual path inside the zip, including any directory prefix your bundler introduced.
Fixes
Verify the module is actually inside the deployed artifact
Do not trust package.json — check the zip. This is the single fastest way to distinguish a packaging failure from a code failure, and it takes a few seconds.
bash# What did we actually ship?
aws lambda get-function --function-name my-function \
--query 'Code.Location' --output text | xargs curl -s -o /tmp/fn.zip
unzip -l /tmp/fn.zip | grep -i 'node_modules/lodash'
Install production dependencies for the right platform
Build the package the way Lambda will run it. If any dependency has native bindings, that means installing for Linux and the architecture your function uses, not for your laptop.
bashnpm ci --omit=dev \
--os=linux --cpu=x64 \
--foreground-scripts
zip -qr function.zip index.js node_modules package.json
Bundle your dependencies rather than shipping node_modules
A bundler resolves every import at build time and fails the build when one is missing — which turns this runtime error into a compile-time one, where it is far cheaper. It also cuts the package size and, with it, cold-start time.
bashnpx esbuild src/index.js \
--bundle \
--platform=node \
--target=node22 \
--outfile=dist/index.js
Use the v3 SDK on modern runtimes
If the missing module is aws-sdk, the code is written against SDK v2, which is not present on Node 18 or later. Move to the scoped v3 clients, which are available in the runtime, or bundle v2 explicitly if migrating is not yet practical.
js// v2 — not present on Node 18+
// const AWS = require("aws-sdk");
// const s3 = new AWS.S3();
// v3 — available in the runtime
import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";
const s3 = new S3Client({});
Also seen as
The same underlying failure, worded differently by a different runtime, SDK version, or logging layer. All of these land here — there is no separate page for each phrasing.
Related errors
Errors that show up alongside this one, or that people mistake for it.
References
- AWS Lambda Developer Guide — Troubleshoot deployment issues
- AWS Lambda Developer Guide — Deploy Node.js Lambda functions with .zip archives
LogStitch finds this automatically, across every invocation in your account.
Paste a log excerpt into the free web stitcher and see it grouped, classified, and measured in your browser — nothing is uploaded. Or run the Mac app against your own AWS profiles and get the same view over every function you own.