diff --git a/packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts b/packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts index 137f641eb439a..32c9336d96b5a 100644 --- a/packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts +++ b/packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts @@ -51,6 +51,7 @@ export class Bundling implements cdk.BundlingOptions { public readonly image: cdk.BundlingDockerImage; public readonly command: string[]; public readonly environment?: { [key: string]: string }; + public readonly workingDirectory: string; public readonly local?: cdk.ILocalBundling; private readonly relativeEntryPath: string; @@ -89,6 +90,9 @@ export class Bundling implements cdk.BundlingOptions { const bundlingCommand = this.createBundlingCommand(cdk.AssetStaging.BUNDLING_INPUT_DIR, cdk.AssetStaging.BUNDLING_OUTPUT_DIR); this.command = ['bash', '-c', bundlingCommand]; this.environment = props.environment; + // Bundling sets the working directory to cdk.AssetStaging.BUNDLING_INPUT_DIR + // and we want to force npx to use the globally installed esbuild. + this.workingDirectory = '/'; // Local bundling if (!props.forceDockerBundling) { // only if Docker is not forced 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 e3f6a07144b88..c665b862ad93f 100644 --- a/packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts +++ b/packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts @@ -55,6 +55,7 @@ test('esbuild bundling in Docker', () => { 'bash', '-c', 'npx esbuild --bundle /asset-input/lib/handler.ts --target=node12 --platform=node --outfile=/asset-output/index.js --external:aws-sdk --loader:.png=dataurl', ], + workingDirectory: '/', }), }); });