Skip to content

Bug: importing Tracer from powertools v2 causes SyntaxError #2163

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

Closed
webdeveric opened this issue Mar 4, 2024 · 5 comments · Fixed by #2164
Closed

Bug: importing Tracer from powertools v2 causes SyntaxError #2163

webdeveric opened this issue Mar 4, 2024 · 5 comments · Fixed by #2164
Assignees
Labels
bug Something isn't working completed This item is complete and has been merged/shipped tracer This item relates to the Tracer Utility

Comments

@webdeveric
Copy link

Expected Behaviour

No error thrown

Current Behaviour

When running my ESM Lambda's locally, just importing Tracer will cause the following error any time I hit one of my routes.

Runtime.UserCodeSyntaxError: SyntaxError: The requested module 'aws-xray-sdk-core' does not provide an export named 'Segment'

Code snippet

It looks like the issue is how Segment and/or Subsegment are being imported from aws-xray-sdk-core in the transpiled js code.

node -e "import { Tracer } from '@aws-lambda-powertools/tracer';" --input-type=module 

Steps to Reproduce

Create tracer.mjs and put this in it.

import { Tracer } from '@aws-lambda-powertools/tracer';

Run node tracer.mjs

You should see something like this:

[...]node_modules/@aws-lambda-powertools/tracer/lib/esm/provider/ProviderService.js:1
import { captureAWS, captureAWSClient, captureAWSv3Client, captureAsyncFunc, captureFunc, captureHTTPsGlobal, getNamespace, getSegment, setSegment, Segment, setContextMissingStrategy, setDaemonAddress, setLogger, } from 'aws-xray-sdk-core';
                                                                                                                                                    ^^^^^^^
SyntaxError: Named export 'Segment' not found. The requested module 'aws-xray-sdk-core' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'aws-xray-sdk-core';
const { captureAWS, captureAWSClient, captureAWSv3Client, captureAsyncFunc, captureFunc, captureHTTPsGlobal, getNamespace, getSegment, setSegment, Segment, setContextMissingStrategy, setDaemonAddress, setLogger, } = pkg;

Possible Solution

import pkg from 'aws-xray-sdk-core';
const { Segment } = pkg;

Powertools for AWS Lambda (TypeScript) version

2.0.1

AWS Lambda function runtime

20.x

Packaging format used

npm

Execution logs

No response

@webdeveric webdeveric added triage This item has not been triaged by a maintainer, please wait bug Something isn't working labels Mar 4, 2024
Copy link

boring-cyborg bot commented Mar 4, 2024

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #typescript channel on our Powertools for AWS Lambda Discord: Invite link

@webdeveric webdeveric changed the title importing Tracer from powertools v2 causes SyntaxError Bug: importing Tracer from powertools v2 causes SyntaxError Mar 4, 2024
@dreamorosi dreamorosi self-assigned this Mar 5, 2024
@dreamorosi dreamorosi moved this from Triage to Working on it in Powertools for AWS Lambda (TypeScript) Mar 5, 2024
@dreamorosi dreamorosi added tracer This item relates to the Tracer Utility confirmed The scope is clear, ready for implementation and removed triage This item has not been triaged by a maintainer, please wait labels Mar 5, 2024
@dreamorosi
Copy link
Contributor

Hi, thank you for reporting the issue and for also providing a workaround.

I was able to reproduce it on my end and I am working on a fix.

@dreamorosi
Copy link
Contributor

The PR with the fix is up and ready for review, within the next ~8hrs the next maintainer should come online and be able to review it.

Once that's done we'll be able to make a release with the fix. Thanks for your patience and apologies for the inconvenience.

@dreamorosi dreamorosi moved this from Working on it to Pending review in Powertools for AWS Lambda (TypeScript) Mar 5, 2024
@github-project-automation github-project-automation bot moved this from Pending review to Coming soon in Powertools for AWS Lambda (TypeScript) Mar 5, 2024
Copy link
Contributor

github-actions bot commented Mar 5, 2024

⚠️ COMMENT VISIBILITY WARNING ⚠️

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.

@github-actions github-actions bot added pending-release This item has been merged and will be released soon and removed confirmed The scope is clear, ready for implementation labels Mar 5, 2024
Copy link
Contributor

github-actions bot commented Mar 5, 2024

This is now released under v2.0.2 version!

@github-actions github-actions bot added completed This item is complete and has been merged/shipped and removed pending-release This item has been merged and will be released soon labels Mar 5, 2024
@dreamorosi dreamorosi moved this from Coming soon to Shipped in Powertools for AWS Lambda (TypeScript) Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working completed This item is complete and has been merged/shipped tracer This item relates to the Tracer Utility
Projects
Development

Successfully merging a pull request may close this issue.

2 participants