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

(@aws-cdk/aws-lambda-nodejs): ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL  Cannot read properties of undefined #26381

Open
Dzhuneyt opened this issue Jul 16, 2023 · 1 comment
Labels
@aws-cdk/aws-lambda-nodejs bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@Dzhuneyt
Copy link
Contributor

Describe the bug

Can not use new NodejsFunction() with esbuild in a PNPM monorepo setup.

Expected Behavior

Commands like cdk synth succeed.

Current Behavior

Commands like cdk synth fail.

Reproduction Steps

  1. git clone [email protected]:awesome-cdk/aws-cdk-nodejsfunction-issue.git
  2. cd aws-cdk-nodejsfunction-issue
  3. pnpm install
  4. cd packages/cdk
  5. pnpm exec cdk synth

More detailed description of the issue:

  1. Create a monorepo setup, orchestrated by PNPM as a package and dependency manager. E.g. have packages/frontend for your frontend and packages/cdk for your IaC and backend.
  2. Use the new NodejsFunction() construct anywhere in the CDK app
  3. Decide to use esbuild for local bundling, instead of Docker, because it's faster and more efficient
  4. Install dependencies at monorepo root using pnpm install
  5. Try to synthesize the CDK app: cdk synth

Also see the recent GitHub Actions failure in the minimum reproducable repo for a simple example that fails.

Possible Solution

When trying to use esbuild to compile the Lambda TS into JS, it seems that the construct executes a command like this bash -c pnpm exec -- esbuild --bundle ... at the monorepo root. Instead, the command should be executed from the context of the CDK package root (in this case, ./packages/cdk).

I have verified this by running these very trivial commands:
At the monorepo root - doesn't work:
pnpm exec esbuild --help
At packages/cdk - works:
pnpm exec esbuild --help

Additional Information/Context

No response

CDK CLI Version

2.85.0 (build 4e0d726)

Framework Version

No response

Node.js Version

18.16.0

OS

MacOS

Language

Typescript

Language Version

No response

Other information

No response

@Dzhuneyt Dzhuneyt added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 16, 2023
@Dzhuneyt Dzhuneyt changed the title (@aws-cdk/aws-lambda-nodejs ): ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL  Cannot read properties of undefined (@aws-cdk/aws-lambda-nodejs): ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL  Cannot read properties of undefined Jul 16, 2023
@peterwoodworth peterwoodworth added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jul 17, 2023
@peterwoodworth
Copy link
Contributor

Might be related to #24021

@khushail khushail added the node18-upgrade Any work (bug, feature) related to Node 18 upgrade label Sep 1, 2023
@rix0rrr rix0rrr removed the node18-upgrade Any work (bug, feature) related to Node 18 upgrade label Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda-nodejs bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

4 participants