Skip to content

Unable to bundle CDK lambdas when executed through vitest #1544

@Poliziano

Description

@Poliziano

Describe the bug

Using vitest to test CDK stacks fails when the stack constructs a nodes lambda. When using jest the tests run without issue. I have no idea if the is a problem with CDK or vitest, or something else entirely.

Failed to bundle asset MyTestStack/my-lambda/Code/Stage, bundle output is located at /private/var/folders/wf/0n_3mjr91114bj87w744lyvm0000gn/T/cdk.outRqpmmh/bundling-temp-31e6d62c5dd7767fc416ae362fc44caa01c8c1f300c419c61d1f3663ad52c8ff-error: TypeError [ERR_INVALID_ARG_VALUE]: The argument 'stdio' is invalid. Received WritableWorkerStdio {
  _writableState: WritableState {
    objectMode: false,
    highWaterMark: 16384,
    finalCalled: false,...
 ❯ AssetStaging.bundle node_modules/aws-cdk-lib/core/lib/asset-staging.js:2:584
 ❯ AssetStaging.stageByBundling node_modules/aws-cdk-lib/core/lib/asset-staging.js:1:4201
 ❯ stageThisAsset node_modules/aws-cdk-lib/core/lib/asset-staging.js:1:1609
 ❯ Cache.obtain node_modules/aws-cdk-lib/core/lib/private/cache.js:1:242
 ❯ new AssetStaging node_modules/aws-cdk-lib/core/lib/asset-staging.js:1:2004
 ❯ new Asset node_modules/aws-cdk-lib/aws-s3-assets/lib/asset.js:1:736
 ❯ AssetCode.bind node_modules/aws-cdk-lib/aws-lambda/lib/code.js:1:4731
 ❯ new Function node_modules/aws-cdk-lib/aws-lambda/lib/function.js:1:2803
 ❯ new NodejsFunction node_modules/aws-cdk-lib/aws-lambda-nodejs/lib/function.js:1:1171

Reproduction

I have created a repository that demonstrates the issue. For comparison, I have added one test that runs using vitest, and another test that runs using jest.

https://github.com/Poliziano/cdk-vitest-bug

System Info

System:
  OS: macOS 12.4
  CPU: (10) arm64 Apple M1 Pro
  Memory: 261.09 MB / 16.00 GB
  Shell: 5.8.1 - /bin/zsh
Binaries:
  Node: 16.13.2 - ~/Library/pnpm/node
  npm: 8.1.2 - ~/Library/pnpm/npm
Browsers:
  Safari: 15.5
npmPackages:
  vitest: ^0.16.0 => 0.16.0

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions