question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(lambda-nodejs): The argument 'stdio' is invalid.

See original GitHub issue

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.

Expected Behavior

Lambda bundles without issue.

Current Behavior

An exception is thrown:

Failed to bundle asset MyTestStack/my-lambda/Code/Stage, bundle output is located at /private/var/folders/wf/0n_3mjr91114bj87w744lyvm0000gn/T/cdk.out6K0cHJ/bundling-temp-7578a3f1cc7dd93e1afbd82baffb892397b1dfe9a591ccd912f1633c4f34c233-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 Steps

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

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.28.1 (build d035432)

Framework Version

No response

Node.js Version

16.13.2

OS

macOS 12.4

Language

Typescript

Language Version

3.9.7

Other information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
Newbie012commented, Jul 28, 2022

Sorry for bumping this issue, although, I believe it should be kept open. The actual issue here is that you cannot run aws-cdk inside a worker thread, which is what Vitest does behind the scene.

@elthrasher has written a descriptive comment with a reproduction repo.

With a bit of guidance, I’ll be happy to open a PR 😄

4reactions
hanneswidrigcommented, Oct 19, 2022

Vitest running for tests written to verify AWS TypeScript services would be a huge enabler to ESM-first development. Jest is a complete mess to configure correctly when you mix ESM and CommonJS modules together.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node JS Child Process argument is invalid - Stack Overflow
sleep(5) } but when i load it errors with this TypeError [ERR_INVALID_ARG_VALUE]: The argument 'arguments[1]' is invalid. Received 'username: ...
Read more >
AWS Lambda function logging in Node.js
This page describes how to view Lambda function metrics using Amazon CloudWatch for the Node.js runtime.
Read more >
Node.js v19.3.0 Documentation
Function arguments; Callbacks; Object factory; Function factory ... _unrefActive(); DEP0128: modules with an invalid main entry and an index.js file ...
Read more >
Node.js - Scaling Application - Tutorialspoint
Serverless Development with AWS Lambda and NodeJS ... callback The function gets three arguments error, stdout, and stderr which are called with the...
Read more >
Basic Node.js Lambda Function Concepts - Medium
In this three-part-series we'll look at getting a Node.js application which performs image resizing running on AWS Lambda.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found