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

In aws#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`.
  • Loading branch information
jogold committed May 28, 2021
1 parent 8263c78 commit ad61e6e
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 ad61e6e

Please sign in to comment.