-
Notifications
You must be signed in to change notification settings - Fork 154
Bug: ReferenceError: require is not defined in ES module scope when using @aws-lambda-powertools/tracer in ES Module #2605
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
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Hi, thank you for opening this issue. This is a known limitation of the AWS X-Ray SDK for Node.js that doesn't support ESM. If you want to use ESM you need to provide a polyfill for the |
@dreamorosi, thank you for your response. I've noted it and will make the necessary updates. This is very helpful. |
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. |
Expected Behavior
The package should work seamlessly with ES module syntax without throwing a require error.
Current Behavior
I'm encountering an issue when trying to use the @aws-lambda-powertools/tracer package in a TypeScript project configured as an ES module. The error message suggests that there is an internal use of require which is not supported in ES module scope.
Code snippet
//route.ts file
import { APIGatewayProxyResult, Context } from 'aws-lambda';
import { Tracer } from '@aws-lambda-powertools/tracer';
import { AccountController } from './controllers/AccountController.js';
import { loadConfig } from './config.js';
const tracer = new Tracer({ serviceName: 'transflowAccountService' });
export const updateAccountHandler = async (event: any, context: Context): Promise => {
tracer.getSegment();
};
Steps to Reproduce
{
"compilerOptions": {
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"declaration": true,
"declarationMap": true,
"forceConsistentCasingInFileNames": true,
"noEmitOnError": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"removeComments": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"resolveJsonModule": true,
"pretty": true,
"sourceMap": true,
"strict": true,
"module": "esnext",
"moduleResolution": "node",
"target": "es2019",
"outDir": "build",
"rootDir": "src",
"lib": ["es2019", "DOM"]
},
"ts-node": {
"esm": true,
"experimentalSpecifierResolution": "node",
},
"exclude": ["node_modules", "built"],
// "include": ["src/.ts", "src/**/.ts"]
"include": ["src/**/*"],
}
Possible Solution
No response
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
20.x
Packaging format used
npm
Execution logs
The text was updated successfully, but these errors were encountered: