Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pipelines: Calling npm ci only works after updating npm #23343

Closed
estrehle opened this issue Dec 14, 2022 · 9 comments
Closed

pipelines: Calling npm ci only works after updating npm #23343

estrehle opened this issue Dec 14, 2022 · 9 comments
Assignees
Labels
@aws-cdk/pipelines CDK Pipelines library closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. documentation This is a problem with documentation. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@estrehle
Copy link

estrehle commented Dec 14, 2022

The CDK pipelines example contains the following synth step:

const pipeline = new pipelines.CodePipeline(this, 'Pipeline', {
  synth: new pipelines.ShellStep('Synth', {
    ...
    commands: [
      'npm ci',
      'npm run build',
      'npx cdk synth',
    ],
  }),
});

When I tried this, however, my pipelines failed at the npm ci command with a strange error message:

[Container] 2022/12/14 16:00:37 Running command npm ci
npm ERR! Cannot read property 'aws-cdk-lib' of undefined

The package aws-cdk-lib was the first entry in my package.json dependencies. So it seems like CodeBuild was not able to parse my dependencies when installing via npm ci.

The reason that npm ci does not work is that CodeBuild uses an old version of npm. When I checked, the newest release was 9.2.0 and CodeBuild was using 6.14.17.

Updating npm before running npm ci fixes the issue:

const pipeline = new pipelines.CodePipeline(this, 'Pipeline', {
  synth: new pipelines.ShellStep('Synth', {
    ...
    // Update npm before running commands
    installCommands: ['npm i -g npm@latest'],
    commands: [
      'npm ci',
      'npm run build',
      'npx cdk synth',
    ],
  }),
});

I would suggest adding the installCommands line in the documentation so other users can avoid this issue.

Stackoverflow issue: Link
Minimum working example with issue and fix: Link

Links

https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.pipelines-readme.html

@estrehle estrehle added documentation This is a problem with documentation. needs-triage This issue or PR still needs to be triaged. labels Dec 14, 2022
@github-actions github-actions bot added the @aws-cdk/pipelines CDK Pipelines library label Dec 14, 2022
@khushail khushail added the investigating This issue is being investigated and/or work is in progress to resolve the issue. label Dec 15, 2022
@khushail khushail self-assigned this Dec 15, 2022
@khushail
Copy link
Contributor

Hi @estrehle , I tried to repro the issue and got an error at build stage(not at the "npm ci"). Could you please share some more information to help me in repro of the issue?
As I got the build failure error, I implemented the fix you provided which did not work. From my understanding , it seems like the issue lies with "npm build" command as this package seems to be outdated. But even that would need more investigation.
Could you please try to remove the "npm build" command and see if that works for you? (with initial code sample provided in documentation)

@khushail khushail added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. needs-triage This issue or PR still needs to be triaged. labels Dec 22, 2022
@github-actions
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Dec 25, 2022
@ericljiang
Copy link

I can confirm the bug and the suggested fix.

@DASPRiD
Copy link

DASPRiD commented Feb 10, 2023

From what I can tell, this is due to the package-lock.json being lock version 3, while the npm version on code build is only supporting up to lock version 2.

@ekeyser
Copy link

ekeyser commented Feb 20, 2023

This has impacted me as well. I'm confused why this started happening recently. I don't have an exact time other than the past few months but I have multiple pipelines that were created using cdkv2 and now with an update of cdk version number (v2.58.0 -> v2.65.0 in at least one case) completely breaks the pipeline synth step specifically on the npm ci command.

Going to investigate @DASPRiD 's comment. Not sure what lock versions are w/re: to package-lock.json.

Perhaps I'm not understanding something but I don't believe you can modify the cdk code to adjust the behavior because the self-mutate step never has a chance to execute. One must navigate to the CodeBuild project for the pipeline and directly modify the npm commands in the buildspec.

Additionally, I took the opportunity to update the pipeline build environment from standard:5.0 to standard:6.0. Once that is accomplished npm ci works w/o the npm i -g npm@latest fix. At least that's what I'm seeing.

OK so this was due to me most recently changing my default node via nvm to v18.

@ericljiang
Copy link

I think this is fixed by #24544

@a-shatou
Copy link

Even after updating npm, it still fails. I currently cannot use CDK to deploy any apps. Is there anyone from AWS working on this?

Screenshot 2023-07-20 at 3 07 24 AM

@cgarvis
Copy link
Contributor

cgarvis commented Jul 20, 2023

We don't have a good mechanism for monitoring comments on closed isseus/prs. If this is still an issue, please create a new issue for us to track.

@ericljiang
Copy link

@a-shatou Works for me using "aws-cdk-lib": "2.81.0"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/pipelines CDK Pipelines library closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. documentation This is a problem with documentation. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

8 participants