diff --git a/packages/aws-serverless/src/awslambda-auto.ts b/packages/aws-serverless/src/awslambda-auto.ts index 9cf3ba68ae6e..2f23fe652005 100644 --- a/packages/aws-serverless/src/awslambda-auto.ts +++ b/packages/aws-serverless/src/awslambda-auto.ts @@ -1,3 +1,5 @@ +// Important: This file cannot import anything other than the index file below. +// This is the entry point to the lambda layer, which only contains the entire SDK bundled into the index file import * as Sentry from './index'; const lambdaTaskRoot = process.env.LAMBDA_TASK_ROOT; @@ -21,7 +23,9 @@ if (lambdaTaskRoot) { ), }); - Sentry.tryPatchHandler(lambdaTaskRoot, handlerString); + if (typeof require !== 'undefined') { + Sentry.tryPatchHandler(lambdaTaskRoot, handlerString); + } } else { throw Error('LAMBDA_TASK_ROOT environment variable is not set'); }