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) a bundler (esbuild >= 0.22) now omits node_modules from the bundle by default; (3) a Lambda layer was built on a different OS/arch than the runtime; (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. esbuild >= 0.22: set `packages: 'bundle'` (or `--packages=bundle`) so dependencies are included again.
  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 EOL2027-02-01.

Find every instance in your project

The free EOLkits scanner runs in your browser (nothing uploaded) and flags this and related breakages across your IaC and dependency files.

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

Get the full migration audit — $299, hash-anchored PDF →