question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(pipelines): 'npx cdk' is failing in version 1.103.0, causing CDK pipelines synth action to fail

See original GitHub issue

CDK Pipeline, when using NPM simple synth action, runs:

  • npm ci to install dependencies (including dev dependencies) according to package-lock.json
  • npx cdk synth to synthesize the app

If aws-cdk is not listed in package’s dependencies, the first command will not install it. Then the npx command will not find aws-cdk locally and installs it. However, it will install the latest version available, so release is not properly versioned. Also, from version 1.103.0 it fails with following message: Cannot find module '.../aws-sdk/scripts/check-node-version.js'.

I would like to raise the following questions:

  • Is it correct and desirable that the pipeline installs dev dependencies? Wouldn’t it be cleaner to only install prod ones using npm ci --production? In that case, aws-cdk would need to become production dependency of each project
  • Would it be better to run npx --no-install cdk synth as synth command, to ensure the pipeline requires the aws-cdk dependecy and cannot just silently use the latest cdk cli?

Anyways, I would assume that for convenience, npx cdk ... should still work without the package being previously installed.

Reproduction Steps

For consistency, I am using aws/codebuild/standard:5.0 docker image that CDK pipelines use for synthesis, can be find here: https://github.com/aws/aws-codebuild-docker-images/tree/master/ubuntu/standard/5.0 and build using docker build -t aws/codebuild/standard:5.0 .

What did you expect to happen?

Previous version (1.102.0) works fine:

tomas@arkham:~$ docker run --rm -it --entrypoint='' aws/codebuild/standard:5.0 npx --package aws-cdk@1.102.0 cdk version
npx: installed 188 in 9.121s
1.102.0 (build a75d52f)
***************************************************
*** Newer version of CDK is available [1.103.0] ***
*** Upgrade recommended                         ***
***************************************************

What actually happened?

Latest version (1.103.0) fails:

tomas@arkham:~$ docker run --rm -it --entrypoint='' aws/codebuild/standard:5.0 npx cdk version
internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module '/root/.npm/_npx/1/lib/node_modules/cdk/node_modules/aws-cdk/node_modules/aws-sdk/scripts/check-node-version.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! aws-sdk@2.903.0 postinstall: `node scripts/check-node-version.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the aws-sdk@2.903.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-05-12T10_51_22_468Z-debug.log
Install for [ 'cdk@latest' ] failed with code 1

Environment

  • CDK CLI Version : 1.103.0
  • Framework Version: N/A
  • Node.js Version: v14.15.4
  • OS : CodeBuild standard:5.0 container image
  • Language (Version): TypeScript

This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
rix0rrrcommented, May 18, 2021
env NPM_CONFIG_UNSAFE_PERM=true npx my-demo-postinstall-plugin@1.0.0
1reaction
rix0rrrcommented, May 18, 2021

Ha-haaah here is the magic:

$ npm set unsafe-perm true
Read more comments on GitHub >

github_iconTop Results From Across the Web

aws-cdk/pipelines module - AWS Documentation - Amazon.com
This module contains two sets of APIs: an original and a modern version of CDK Pipelines. The modern API has been updated to...
Read more >
aws-cdk.pipelines - PyPI
You define how to build and synth the project by specifying a synthAction . This can be any CodePipeline action that produces an...
Read more >
aws-cdk | Yarn - Package Manager
The AWS Cloud Development Kit (AWS CDK) is an open-source software development framework to define cloud infrastructure in code and provision it through...
Read more >
CLI version in CodeBuild is not compatible with the library ...
Figured it out. I was using npx cdk synth command which always used an older version of CDK. Using npx aws-cdk synth uses...
Read more >
Amazon.CDK.Pipelines 1.184.0 - NuGet
Version Downloads Last updated 1.184.0 27 a day ago 1.183.0 71 8 days ago 1.182.0 70 15 days ago
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found