-
Notifications
You must be signed in to change notification settings - Fork 154
Bug: require() command in ES module, stopping lambda from running #2464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, this is a known limitation of AWS X-Ray SDK that doesn't support ESM fully and requires monkey patching the Are you by chance bundling your code? If so, you can insert a banner to polyfill the The example shows how to do this with |
Thank you @dreamorosi for your quick response. I forget about the upgrade guide. At this time we are not using a bundler (yet). I will close this ticket then, hopefully the X-Ray SDK starts to support ESM as well :) |
This issue is now closed. Please be mindful that future comments are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so. |
This issue is now closed. Please be mindful that future comments are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so. |
I faced the same issue using webpack as my bundler. I used its Banner Plugin to solve this: new webpack.BannerPlugin({
banner: "import { createRequire } from 'module';const require = createRequire(import.meta.url);",
raw: true
}) |
Expected Behavior
If captureHTTPsRequests is set to true that it works within an ES Modules project.
Current Behavior
Code snippet
Within the function
ProviderService.captureHTTPsGlobal
a require statement in included, which halts ES modules.File
@aws-lambda-powertools/tracer/lib/esm/provider/ProviderService.js:27:9
Steps to Reproduce
index.mjs
, with a simple tracer config, as long ascaptureHTTPsRequests: true
is set.Possible Solution
I've not explored the solution, but you could try to use dynamic import instead of requires for ES Modules projects.
Powertools for AWS Lambda (TypeScript) version
2.1.0
AWS Lambda function runtime
20.x
Packaging format used
npm
Execution logs
The text was updated successfully, but these errors were encountered: