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

Error: There is already a Construct with name 'TypeScriptSource' in BucketDeployment #993

Closed
george-hm opened this issue Dec 12, 2023 · 4 comments · Fixed by #1016
Closed
Labels
bug Something isn't working

Comments

@george-hm
Copy link

Describe the bug
When adding multiple sources (e.g. 2 TypescriptSource's) to a BucketDeployment construct, there is an error:

Error: There is already a Construct with name 'TypeScriptSource' in BucketDeployment

To Reproduce
Create two TypescriptSource's (or two JavaScriptSource, the error happens for either) and add them to a bucket deployment
Example:

const sourceOne = new TypeScriptSource('sourceOne.ts', {
    buildOptions: {
        outfile: 'sourceOne.js',
    },
});
const sourceTwo = new TypeScriptSource('sourceTwo.ts', {
    buildOptions: {
        outfile: 'sourceTwo.js',
    },
});

new BucketDeployment(this, 'EmbedassetsDeployment', {
    destinationBucket: myBucket,
    sources: [
        sourceOne,
        sourceTwo,
    ],
});

Expected behavior
No error and able to deploy successfully

Versions:

  • CDK: ^2.41.0
  • Node.js: v18.18.2

Additional context
I believe this issue stems from the consistent ID set for creating a new s3Asset which is done here:
/~https://github.com/mrgrain/cdk-esbuild/blob/v5/src/source.ts#L69

It would be good if this ID is generated based on something so it is more unique

Looking at the full stacktrace hints at this problem:

Error: There is already a Construct with name 'TypeScriptSource' in BucketDeployment [EmbedassetsDeployment]
    at Node.addChild (/redacted/node_modules/constructs/src/construct.ts:403:13)
    at new Node (/redacted/node_modules/constructs/src/construct.ts:71:17)
    at new Construct (/redacted/node_modules/constructs/src/construct.ts:463:17)
    at new Asset (/redacted/node_modules/aws-cdk-lib/aws-s3-assets/lib/asset.js:1:473)
    at new EsbuildAsset (/redacted/node_modules/@mrgrain/cdk-esbuild/src/asset.ts:104:5)
    at new TypeScriptAsset (/redacted/node_modules/@mrgrain/cdk-esbuild/src/asset.ts:135:1)
    at TypeScriptSource.bind (/redacted/node_modules/@mrgrain/cdk-esbuild/src/source.ts:76:20)
    at /redacted/node_modules/aws-cdk-lib/aws-s3-deployment/lib/bucket-deployment.js:1:2867
    at Array.map (<anonymous>)
    at new BucketDeployment (/redacted/node_modules/aws-cdk-lib/aws-s3-deployment/lib/bucket-deployment.js:1:2848)
@george-hm george-hm added the bug Something isn't working label Dec 12, 2023
@mrgrain
Copy link
Owner

mrgrain commented Dec 12, 2023

Ah good catch!

@mergify mergify bot closed this as completed in #1016 Dec 24, 2023
mergify bot pushed a commit that referenced this issue Dec 24, 2023
Fixes #993

(cherry picked from commit 6777ba2)

# Conflicts:
#	src/source.ts
mergify bot pushed a commit that referenced this issue Dec 24, 2023
Fixes #993

(cherry picked from commit 6777ba2)

# Conflicts:
#	src/source.ts
@mrgrain
Copy link
Owner

mrgrain commented Dec 24, 2023

Hey @george-hm Sorry this took so long. It's fixed in v5.0.8.
Fixes for v3 and v4 are coming as well, please LMK if you need these prioritized.

mrgrain added a commit that referenced this issue Dec 24, 2023
@george-hm
Copy link
Author

@mrgrain no worries we were wrapping up for the holidays anyhow!

Thanks for the fix, we have upgraded to v5

@mrgrain
Copy link
Owner

mrgrain commented Jan 8, 2024

Updating to v5 is great. It's also fixed for v3 and v4 now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants