Skip to content

Bug: Dynamic require error with ESM functions #2290

Closed
@lukehedger

Description

@lukehedger

Expected Behaviour

ESM Lambda function with Tracer enabled should be invoked without error

Current Behaviour

Lambda invocation error received:

{
  "errorType": "Error",
  "errorMessage": "Dynamic require of \"util\" is not supported",
  "trace": [
    "Error: Dynamic require of \"util\" is not supported",
    "    at file:///var/task/index.mjs:1:382",
    "    at <anonymous> (/node_modules/cls-hooked/context.js:4:14)",
    "    at file:///var/task/index.mjs:1:458",
    "    at <anonymous> (/node_modules/aws-xray-sdk-core/dist/lib/context_utils.js:5:11)",
    "    at file:///var/task/index.mjs:1:458",
    "    at <anonymous> (/node_modules/aws-xray-sdk-core/dist/lib/aws-xray.js:2:20)",
    "    at file:///var/task/index.mjs:1:458",
    "    at <anonymous> (/node_modules/aws-xray-sdk-core/dist/lib/index.js:3:18)",
    "    at file:///var/task/index.mjs:1:458",
    "    at <anonymous> (/node_modules/@aws-lambda-powertools/tracer/lib/esm/provider/ProviderService.js:1:21)"
  ]
}

Code snippet

Lambda function with following configuration in CDK app (some options removed for brevity):

new NodejsFunction(this, "MyFunction", {
  architecture: Architecture.ARM_64,
  bundling: {
    format: OutputFormat.ESM,
  },
  runtime: Runtime.NODEJS_20_X,
  tracing: Tracing.ACTIVE,
})

Steps to Reproduce

  1. Deploy an ESM Lambda function with Tracer
  2. Invoke function
  3. Observe error

Possible Solution

No response

Powertools for AWS Lambda (TypeScript) version

latest

AWS Lambda function runtime

20.x

Packaging format used

npm

Execution logs

No response

Metadata

Metadata

Assignees

Labels

need-responseThis item requires a response from a customer and will considered stale after 2 weeksnot-a-bugNew and existing bug reports incorrectly submitted as bugtracerThis item relates to the Tracer Utility

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions