AWS Lambda

Runtime.ImportModuleError: Error: Cannot find module

Runtime.ImportModuleError: Error: Cannot find module

What it means

Lambda can't load a dependency your handler imports — most often after a runtime upgrade changed what's bundled.

Why it happens

Common right after changing the runtime: (1) on nodejs18+ the AWS SDK v2 ('aws-sdk') is no longer preinstalled — only @aws-sdk v3 is; (2) the deployment bundle omitted a dependency; (3) a Lambda layer was built on a different OS/architecture; or (4) a native binary needs a different glibc. The handler then throws ImportModuleError at cold start.

How to fix it

  1. If it names `aws-sdk` on nodejs18+: migrate to @aws-sdk v3 modular clients, or bundle aws-sdk v2 explicitly (see the dedicated /fix page).
  2. Inspect the built ZIP or image and the bundler's current configuration to confirm the named dependency is actually included.
  3. Build layers/packages on the runtime's base image (e.g. `public.ecr.aws/lambda/nodejs:22`) and match the architecture (x86_64 vs arm64).
  4. Confirm the module is where Lambda expects it (`nodejs/node_modules/...` for a layer; top level for a function package) and that the handler string matches the file path.

Related deadline: Lambda Node.js 18 create/update restrictions2027-02-01.

Check configured patterns in your project

The free EOLkits scanner processes files in your browser and flags selected related patterns in supported IaC and dependency files. File names and contents are not uploaded; bounded aggregate file and finding counts may be sent. It is not a complete source or AWS-account scan.

Prefer a 10-second check? Paste your config into the free AWS EOL checker. Pasted input is not uploaded; bounded first-party usage events may be sent.

Primary source: https://repost.aws/knowledge-center/lambda-import-module-error-nodejs

Inspect the $299 report sample and availability →