aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

(pipeline): no matching base directory path found for cdk/cdk.out

Open best-cloud opened this issue 1 year ago • 6 comments

Describe the bug

I am using CDK with CodePipeline and CodeBuild, everything works fine in Linux aws/codebuild/standard:6.0.

However, when I upgrade to aws/codebuild/standard:7.0 or Amazon Linux 2 x86_64 standard image, version 5.0, npx cdk synth does nothing, as the result I got the following errors when synthesizing from pipeline.

42 | [Container] 2023/12/29 07:11:14.079166 Running command npx cdk synth
43 |  
44 | [Container] 2023/12/29 07:11:16.641555 Phase complete: BUILD State: SUCCEEDED
45 | [Container] 2023/12/29 07:11:16.641572 Phase context status code:  Message:
46 | [Container] 2023/12/29 07:11:16.683183 Entering phase POST_BUILD
47 | [Container] 2023/12/29 07:11:16.684920 Phase complete: POST_BUILD State: SUCCEEDED
48 | [Container] 2023/12/29 07:11:16.684933 Phase context status code:  Message:
49 | [Container] 2023/12/29 07:11:16.770308 Expanding base directory path: cdk/cdk.out
50 | [Container] 2023/12/29 07:11:16.773789 Assembling file list
51 | [Container] 2023/12/29 07:11:16.773807 Expanding cdk/cdk.out
52 | [Container] 2023/12/29 07:11:16.776932 Skipping invalid file path cdk/cdk.out
53 | [Container] 2023/12/29 07:11:16.777023 Phase complete: UPLOAD_ARTIFACTS State: FAILED
54 | [Container] 2023/12/29 07:11:16.777033 Phase context status code: CLIENT_ERROR Message: no matching base directory path found for cdk/cdk.out

Expected Behavior

cdk/cdk.out should be found

Current Behavior

cdk/cdk.out is not found

Reproduction Steps

export class CdkStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

      const pipeline = new CodePipeline(this, 'Pipeline', {
      pipelineName: 'Pipeline',
      crossAccountKeys: true,
      synth: new ShellStep('Synth', {
        input: xxx,
        commands: ['cd cdk', 'npm ci', 'npm run build', 'npx cdk synth'],
        primaryOutputDirectory: 'cdk/cdk.out'
      }),
      codeBuildDefaults: {
        buildEnvironment: {
          buildImage: LinuxBuildImage.STANDARD_7_0
        }
      }
    })
  }
}

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.117.0 (build 59d9b23)

Framework Version

No response

Node.js Version

20.10.4

OS

Linux

Language

TypeScript

Language Version

No response

Other information

No response

best-cloud avatar Dec 29 '23 07:12 best-cloud

Yes I can reproduce this issue. It fails in STANDARD_7_0 but works in STANDARD_6_0 with exactly the same configuration.

pahud avatar Jan 02 '24 18:01 pahud

Hi team, is there any ETA for this issue?

best-cloud avatar Jan 16 '24 07:01 best-cloud

When I run it using a global installed version (npm i -g aws-cdk) I do get a cdk.out directory locally with the cdk synth command while with the npx cdk synth I got nothing. The package.json version and global version match so I'm not sure why.

Changing npx cdk synth to cdk synth fixed the issue on CodePipeline too, in my case.

vroegop avatar Jan 23 '24 08:01 vroegop

I recently had a version of this error myself. The fix was simple, I updated my cdk.json output path from ../../dist/packages/infra to ../../dist/packages/infra/cdk.out.

Prior to this change cdk.out referred to a JSON file in ../../dist/packages/infra.

indieisaconcept avatar Feb 17 '24 02:02 indieisaconcept

The issue has been there for more than 2 months, is there any plan to fix it?

best-cloud avatar Mar 04 '24 09:03 best-cloud

I ran into this issue when npx cdk synth was accidentally removed from the initial CodePipeline. I tried adding it back and even tried @vroegop suggestion of changing it to just npx synth but it would never recognize the code changes and kept throwing the error. I ended up just deleting the pipeline and creating it new :/ I would be nice to know what the proper solution for this to re-recognize the synth and resolve without deletion.

iamface avatar Nov 13 '24 02:11 iamface

I'm confused by this issue, and it looks like we've moved most users over to STANDARD_7 in https://github.com/aws/aws-cdk/issues/26810, and it doesn't look like a huge explosion of complaints of a broken pipeline has surfaced because of that.

Is this still a problem?

rix0rrr avatar Jun 19 '25 14:06 rix0rrr

I am getting this error, but it might be because of my file structure. Will update if I find a fix.

Aaylen avatar Jun 24 '25 23:06 Aaylen

In my case I had some ShellStep commands' dir wrong up in remote so all changes I pushed where ignored since the cdk pipeline could't self-update with the changes. My solution was to do a cdk deploy with the fix from my workstation and the cdk.out dir was found.

I didn't have to use a global cdk, everything worked fine:

    const cdkPipeline = new cdkpipeline.CodePipeline(
      this,
      "SharedCdkPipeline",
      {
        codePipeline,
        synth: new cdkpipeline.ShellStep("Synth", {
          input: cdkpipeline.CodePipelineSource.connection(
            `${repository.owner}/${repository.name}`,
            repository.branch,
            {
              connectionArn: repository.connectionArn,
              actionName,
            },
          ),
          installCommands: [
            "npm i -g corepack@latest",
            "corepack enable",
            "pnpm i",
          ],
          commands: [
            "pnpm --filter '@coddi/shared...' build", // <-- my error was a typo in the filter
            "pnpm --filter '@coddi/shared' cdk synth",
          ],
          primaryOutputDirectory: "infra/cdk.out",
        }),
        synthCodeBuildDefaults: {
          partialBuildSpec: codebuild.BuildSpec.fromObject({
            version: "0.2",
            phases: {
              install: {
                "runtime-versions": {
                  nodejs: 22,
                },
              },
            },
          }),
        },
        selfMutation: true,
      },
    );

wjes avatar Jun 30 '25 13:06 wjes

When I run it using a global installed version (npm i -g aws-cdk) I do get a cdk.out directory locally with the cdk synth command while with the npx cdk synth I got nothing. The package.json version and global version match so I'm not sure why.

Changing npx cdk synth to cdk synth fixed the issue on CodePipeline too, in my case.

Although the issue is still there, I have finally solved it by using the global CDK. This is a valuable clue, AWS team please debug it ASAP.

best-cloud avatar Jul 02 '25 07:07 best-cloud