Solving Cannot find Module Error in AWS CDK

Borislav Hadzhiev

Last updated: Apr 14, 2022
2 min


# 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

To solve the error, 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:
# 👇️ delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json # 👇️ clean npm cache npm cache clean --force 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 npx aws-cdk synth command.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.