aws / aws/aws-cdk

aws-lambda-nodejs: `charset` props not work

Open
#32,649 1 comment 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-lambda-nodejs bug effort/medium p1 potential-regression
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### 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

- [X] 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**

```ts
// 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**

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

### Reproduction Steps

Restores the process of setting the deleted charset.
```diff

...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.
https://github.com/aws/aws-cdk/commit/3f1f974b1c17003e1cb8c7a39eb6ef64bfe9a06a
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**

```ts
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
},
});
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start in packages/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts around lines 260-262 and compare the current implementation with commit 3f1f974b1c17003e1cb8c7a39eb6ef64bfe9a06a. Verify that Charset.UTF8 causes --charset=utf8 to be passed to esbuild and that the bundled output retains non-ASCII characters.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript, node.js, typescript
Domain
build-system, cloud
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.