Skip to content

cloudformation-diff: Hidden dependency on aws-sdk #28679

@frankpengau

Description

@frankpengau

Describe the bug

We have a custom aws-cdk consruct library that exports cloudformation-diff.

Since @aws-cdk/cloudformation-diff for version 2.119.0, it is throwing the following error:

node_modules/@aws-cdk/cloudformation-diff/lib/diff-template.d.ts:1:32 - error TS2307: Cannot find module 'aws-sdk' or its corresponding type declarations.

1 import { CloudFormation } from 'aws-sdk';
                                 ~~~~~~~~~


Found 1 error in node_modules/@aws-cdk/cloudformation-diff/lib/diff-template.d.ts:1

We believe the error is coming from changes in this PR: #28336

Specifically in packages/@aws-cdk/cloudformation-diff/lib/diff-template.ts, the following change:

// The SDK is only used to reference `DescribeChangeSetOutput`, so the SDK is added as a devDependency.
// The SDK should not make network calls here
// eslint-disable-next-line import/no-extraneous-dependencies
import { CloudFormation } from 'aws-sdk';

I have a sample repo to reproduce the exact issue: https://github.com/frankpengau/cdk-lib-cfn-diff-issue-20240112

Expected Behavior

It should not have a missing dependency.

Current Behavior

It currently has an indirect dependency on aws-sdk causing our construct library to have a transitive dependency on aws-sdk. If it is indeed a dependency, it should be added in as such, instead of being only a devdependency.

Reproduction Steps

  1. cdk init lib --language typescript
  2. Install @aws-cdk/cloudformation-diff for version 2.119.0
  3. In a new file in lib folder: export * as cfndiff from @aws-cdk/cloudformation-diff
  4. Compile typescript tsc

Possible Solution

Explicit dependency on aws-sdk, so that it shows up in the package-lock.json file and installs it as necessary for @aws-cdk/cloudformation-diff to work.

Additional Information/Context

No response

CDK CLI Version

2.114.1

Framework Version

No response

Node.js Version

18.13.0

OS

macOS

Language

TypeScript

Language Version

TypeScript (5.2.2)

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions