From b19da053cffb40400406ce6ece4ffe15a0400882 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Sun, 30 May 2021 13:23:57 +0200 Subject: [PATCH] fix(lambda-nodejs): cannot bundle locally when consuming a node module with a NodejsFunction (#14914) #14739 changed how `esbuild` is run. It now uses the package manager. When consuming a node module with a `NodejsFunction` we need to run `esbuild` from the directory containing the lock file. This is where we have `node_modules\.bin`. If we run it from the directory containing the entry file the package manager doesn't "see" `node_modules\.bin`. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts | 2 +- packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts b/packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts index 240114fbfa43d..14020859b296d 100644 --- a/packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts +++ b/packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts @@ -174,7 +174,7 @@ export class Bundling implements cdk.BundlingOptions { osPlatform, }); const environment = this.props.environment ?? {}; - const cwd = path.dirname(this.props.entry); + const cwd = path.dirname(this.props.depsLockFilePath); return { tryBundle(outputDir: string) { diff --git a/packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts b/packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts index 5a2549e8fbfc6..45556403d8398 100644 --- a/packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts +++ b/packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts @@ -299,7 +299,7 @@ test('Local bundling', () => { expect.arrayContaining(['-c', expect.stringContaining(entry)]), expect.objectContaining({ env: expect.objectContaining({ KEY: 'value' }), - cwd: '/project/lib', + cwd: '/project', }), );