Installation Error – AWS CDK

While starting my journey with AWS CDKs (Cloud Development Kit), I encountered the below error in the very first step of the installation of AWS CDK on my Ubuntu 22.04 system.

Installation Command

npm install -g aws-cdk

While the command run through without any error, I observed Warning messages related to the version of nodejs.

npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'engine-test@1.0.0',
npm WARN EBADENGINE   required: { node: '>=15.0.0' },
npm WARN EBADENGINE   current: { node: 'v14.15.0', npm: '7.5.3' }
npm WARN EBADENGINE }
found 0 vulnerabilities

Checking CDK version, I observed, CDK is not either installed or working properly, as expected.

root@dev-Lenovo-G50-80:/home/dev/awscookbook# cdk version
/usr/local/lib/node_modules/aws-cdk/lib/index.js:12422
    home = path.join((os.userInfo().homedir ?? os.homedir()).trim(), ".cdk");
                                             ^

SyntaxError: Unexpected token '?'
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/aws-cdk/bin/cdk.js:3:15)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)

Solution

I suspected CDKs are not installed properly, hence went back to the warning observed when I ran the installation command. The error was related to the version of nodejs, with the requirement stating a higher version was needed, for installation to go through.

There were a couple of blogs related to similar errors, and the solution provided was defining the engines property in your package.json file. I tried it, but unfortunately, the solution didn’t work for me.

I moved to my next step of troubleshooting, wherein I planned to upgrade the nodejs version. I planned to use Node Version Manager for it, hence installed nvm first.

root@dev-Lenovo-G50-80:/home/dev/awscookbook# curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
root@dev-Lenovo-G50-80:/home/dev/awscookbook# nvm --version
0.38.0

Next, I checked local and remotely available versions.

root@dev-Lenovo-G50-80:/home/dev/awscookbook# nvm ls

               
->       system
iojs -> N/A (default)
node -> stable (-> N/A) (default)
unstable -> N/A (default)

root@dev-Lenovo-G50-80:/home/dev/awscookbook# nvm ls-remote | grep "Latest LTS"
         v4.9.1   (Latest LTS: Argon)
        v6.17.1   (Latest LTS: Boron)
        v8.17.0   (Latest LTS: Carbon)
       v10.24.1   (Latest LTS: Dubnium)
      v12.22.12   (Latest LTS: Erbium)
       v14.21.1   (Latest LTS: Fermium)
->     v16.18.1   (Latest LTS: Gallium)
       v18.12.1   (Latest LTS: Hydrogen)

For my setup, I chose the “n-1” LTS release, which is v.16.18.1.

root@dev-Lenovo-G50-80:/home/dev/awscookbook# nvm install  v16.18.1
Downloading and installing node v16.18.1...
Downloading https://nodejs.org/dist/v16.18.1/node-v16.18.1-linux-x64.tar.xz...
########################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v16.18.1 (npm v8.19.2)
Creating default alias: default -> v16.18.1

Lastly, I re-ran the CDK installation and it worked this time.

root@dev-Lenovo-G50-80:/home/dev/awscookbook# npm install -g aws-cdk

added 1 package, and audited 2 packages in 3s

found 0 vulnerabilities


root@dev-Lenovo-G50-80:/home/dev/awscookbook# cdk version
2.51.1 (build 3d30cdb)
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s