After successful installation aws-cdk, cdk command not found

Viewed 3950

I am installing aws-cdk on windows using powershell,

First I was getting Error : "\AppData\Roaming\npm' npm ERR! enoent This is related to npm not being able to find a file."

during installation. I fixed that by creating folder "\AppData\Roaming\npm" as recommended by some solution.

Now my installation is successful with "npm i -g aws-cdk". No error reported,

but when I do "cdk --version" I am getting "cdk : The term 'cdk' is not recognized as the name of a cmdlet, function, script file, or operable program."

"npm -g ls --depth=0" returns C:\Users<username>\AppData\Roaming\npm `-- aws-cdk@1.72.0

4 Answers
  1. Install AWS-CDK:

    npm i -g aws-cdk
    
  2. run below command to set path of environment variable:

    setx PATH "D:\Users\<username>\AppData\Roaming\npm"
    
  3. close the command prompt once above command successfully executed.

  4. open command prompt as new session and run below command:

    cdk --version
    

There are many reasons this could be happening, some of them likely Windows-specific. It is probably worth it to chase down the issue, but for a quick "just get the command running" solution, you can use npx to install-and-execute rather than npm to install.

$ npx -p aws-cdk cdk --version
1.72.0 (build c2f38e8)
$

The above solution may work, but I was able to make mine work by adding "\AppData\Roaming\npm" to user Path variable.

If you made the mistake of installing cdk with pip at some point in time, make sure to remove it.

pip uninstall cdk

You could check if you have it installed with:

pip list | grep cdk
Related