Skip to content

Commit

Permalink
fix(lambda-nodejs): cannot bundle locally when consuming a node modul…
Browse files Browse the repository at this point in the history
…e 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*
  • Loading branch information
jogold authored May 30, 2021
1 parent f62facb commit 52da59c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}),
);

Expand Down

0 comments on commit 52da59c

Please sign in to comment.