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-lambda-nodejs): does not properly construct the (local esbuild) build command when used with pnpm #15460

Closed
adrian-grajdeanu opened this issue Jul 8, 2021 · 3 comments
Assignees
Labels
@aws-cdk/aws-lambda-nodejs bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@adrian-grajdeanu
Copy link

adrian-grajdeanu commented Jul 8, 2021

On a Pnpm driven project this is the command that is generated for local bundling with esbuild:

pnpm exec esbuild -- --bundle "[project-root]/[code-path]/handler.ts" --target=node14 --platform=node --outfile="[project-root]/cdk.out/bundling-temp-8b6ed390c45688293451e8952dff247026fe61f6e0615cf20e46df2b884014ec/index.js" --external:aws-sdk

The problem stems from aws-lambda-nodejs/lib/package-manager.js where PackageManager.PNPM has argSeparator: '--'. PackageManager.runBinCommand includes this argSeparator. Alas, esbuild does not like the -- particle and fails.

What did you expect to happen?

I expect cdk synth to not fail.

What actually happened?

$ cdk synth
Bundling asset SampleStack/HelloHitCounter/HitCounterHandler/Code/Stage...
 > error: Invalid build flag: "--"
...
$

Environment

  • CDK CLI Version : 1.111.0 (build 556ca93)
  • Framework Version: ?
  • Node.js Version: v14.17.3
  • **OS : Ubuntu 18.04.5 LTS (Bionic Beaver)
  • Language (Version): TypeScript (4.3.5)

Other

$ cdk synth
Bundling asset SampleStack/HelloHitCounter/HitCounterHandler/Code/Stage...
 > error: Invalid build flag: "--"

1 error

[project-root]/node_modules/.pnpm/@aws-cdk+core@1.111.0/node_modules/@aws-cdk/core/lib/asset-staging.ts:397
      throw new Error(`Failed to bundle asset ${this.node.path}, bundle output is located at ${bundleErrorDir}: ${err}`);
            ^
Error: Failed to bundle asset SampleStack/HelloHitCounter/HitCounterHandler/Code/Stage, bundle output is located at [project-root]/cdk.out/bundling-temp-03b8e3b2c19c7f30a4d381b35d81ac1ce517d3589cee0fcf5b77aa16c7fe1ae1-error: Error: bash exited with status 1
    at AssetStaging.bundle ([project-root]/node_modules/.pnpm/@aws-cdk+core@1.111.0/node_modules/@aws-cdk/core/lib/asset-staging.ts:397:13)
    at AssetStaging.stageByBundling ([project-root]/node_modules/.pnpm/@aws-cdk+core@1.111.0/node_modules/@aws-cdk/core/lib/asset-staging.ts:246:10)
    at stageThisAsset ([project-root]/node_modules/.pnpm/@aws-cdk+core@1.111.0/node_modules/@aws-cdk/core/lib/asset-staging.ts:137:35)
    at Cache.obtain ([project-root]/node_modules/.pnpm/@aws-cdk+core@1.111.0/node_modules/@aws-cdk/core/lib/private/cache.ts:24:13)
    at new AssetStaging ([project-root]/node_modules/.pnpm/@aws-cdk+core@1.111.0/node_modules/@aws-cdk/core/lib/asset-staging.ts:162:44)
    at new Asset ([project-root]/node_modules/.pnpm/@aws-cdk+aws-s3-assets@1.111.0/node_modules/@aws-cdk/aws-s3-assets/lib/asset.ts:68:21)
    at AssetCode.bind ([project-root]/node_modules/.pnpm/@aws-cdk+aws-lambda@1.111.0/node_modules/@aws-cdk/aws-lambda/lib/code.ts:180:20)
    at new Function ([project-root]/node_modules/.pnpm/@aws-cdk+aws-lambda@1.111.0/node_modules/@aws-cdk/aws-lambda/lib/function.ts:327:29)
    at new NodejsFunction ([project-root]/node_modules/.pnpm/@aws-cdk+aws-lambda-nodejs@1.111.0/node_modules/@aws-cdk/aws-lambda-nodejs/lib/function.ts:51:5)
    at new HitCounter ([project-root]/[code-path]/handler.ts:25:20)
Subprocess exited with error 1
$

The relevant lines in handler.ts are:

import * as cdk from '@aws-cdk/core';
import * as lambda from '@aws-cdk/aws-lambda';
import * as lambdajs from '@aws-cdk/aws-lambda-nodejs';
//...
export class HitCounter extends cdk.Construct {
  constructor(scope: cdk.Construct, id: string, props: any) {
    super(scope, id);
    // ...
    this.handler = new lambdajs.NodejsFunction(this, 'HitCounterHandler', {   // <--- this is line 25
      runtime: lambda.Runtime.NODEJS_14_X,
      handler: 'handler',
      entry: '[code-path]/handler.ts',
    });
  }
}

This is 🐛 Bug Report

@jogold
Copy link
Contributor

jogold commented Jul 9, 2021

The -- has been moved in #15410 (not yet released).

@adrian-grajdeanu
Copy link
Author

Indeed that would fix it. Closing this one.

@github-actions
Copy link

github-actions bot commented Jul 9, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

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. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

3 participants