Solving Cannot find Module Error in AWS CDK


Borislav Hadzhiev

Sat Apr 17 20211 min read


Photo by Amanda Phung

Cannot find module 'aws-cdk/*' Error in AWS CDK #

There are two common reasons why we usually get the "Cannot find module" Error in CDK:

  • we forgot to install a module we've imported
  • we have the necessary packages installed but they are glitched and we have to delete the node_modules directory and run npm install again

I was working on a project yesterday where I had all of the necessary dependencies but I kept getting the error one package name after another:

cannot find module

In order to solve the "Cannot find Module Error" in CDK, we have to:

  1. Check if we have installed all of the CDK packages we're importing. You can run the npm ls command to list all packages, or just go through your package.json file.
  2. If we have all CDK packages installed, remove the node_modules directory and run the install command again:
rm -rf node_modules npm install
  1. If we're missing a package, we have to install it, for example:
npm install --save-exact @aws-cdk/aws-dynamodb@latest

To test whether the issue is resolved - run the cdk synth command.

Further Reading #

Join my newsletter

I'll send you 1 email a week with links to all of the articles I've written that week

Buy Me A Coffee