Skip to content

Commit 1f82e47

Browse files
authored
fix(aws-serverless): Only auto-patch handler in CJS when loading awslambda-auto (#12392)
Guards the `tryPatcHandler` call by checking for the availability of `require` (which is undefined in ESM). In ESM mode, this call fails because `require` is not available. So let's not call it in this case.
1 parent 2eb4c3e commit 1f82e47

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/aws-serverless/src/awslambda-auto.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Important: This file cannot import anything other than the index file below.
2+
// This is the entry point to the lambda layer, which only contains the entire SDK bundled into the index file
13
import * as Sentry from './index';
24

35
const lambdaTaskRoot = process.env.LAMBDA_TASK_ROOT;
@@ -21,7 +23,9 @@ if (lambdaTaskRoot) {
2123
),
2224
});
2325

24-
Sentry.tryPatchHandler(lambdaTaskRoot, handlerString);
26+
if (typeof require !== 'undefined') {
27+
Sentry.tryPatchHandler(lambdaTaskRoot, handlerString);
28+
}
2529
} else {
2630
throw Error('LAMBDA_TASK_ROOT environment variable is not set');
2731
}

0 commit comments

Comments
 (0)