Skip to content

aws-lambda-nodejs: charset props not work #32649

Open
@intptr-t

Description

@intptr-t

Describe the bug

When building TypeScript/JavaScript with aws-lambda-nodejs, the parameter (Charset.UTF8) that does not escape non-ASCII characters does not work.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

v2.85.0

Expected Behavior

If UTF8 is specified for charset, --charset=utf8 is passed to esbuild so that characters are output without escaping.

example expected output

// package/example.ts
var handler = async () => {
  console.log("Japanese:日本語");
};
export {
  handler
};

Current Behavior

Even if UTF8 parameters are passed, escaped strings are always output.

example current output

// package/example.ts
var handler = async () => {
  console.log("Japanese:\u65E5\u672C\u8A9E");
};
export {
  handler
};

Reproduction Steps

Restores the process of setting the deleted charset.

      ...this.props.banner ? [`--banner:js=${JSON.stringify(this.props.banner)}`] : [],
      ...this.props.footer ? [`--footer:js=${JSON.stringify(this.props.footer)}`] : [],
+      ...this.props.charset ? [`--charset=${this.props.charset}`] : [],
      ...this.props.mainFields ? [`--main-fields=${this.props.mainFields.join(',')}`] : [],

https://github.com/aws/aws-cdk/blob/v2.173.2/packages/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts#L260-L262

Possible Solution

No response

Additional Information/Context

The following commit confirms that it has been removed.
3f1f974
file: packages/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts

CDK CLI Version

2.173.2

Framework Version

No response

Node.js Version

v22.11.0

OS

macOS

Language

TypeScript

Language Version

No response

Other information

Example stack code

export class TestStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    new NodejsFunction(this, "Test", {
      entry: "example.ts",
      handler: "index.handler",
      runtime: Runtime.NODEJS_22_X,
      bundling: {
        format: OutputFormat.ESM,
        charset: Charset.UTF8, // <-- This property is not work
      },
    });
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-lambda-nodejsbugThis issue is a bug.effort/mediumMedium work item – several days of effortp1potential-regressionMarking this issue as a potential regression to be checked by team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions