aws / aws/aws-cdk

aws-lambda-nodejs: preCompilation flag: npm run build creates different *.js then npm run cdk diff/deploy

Open
#21,168 16 comments 1 reaction 0 assignees View on GitHub
@aws-cdk/aws-lambda-nodejs bug documentation effort/small p3
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

I'm using the preCompilation flag on the NodejsFunction (version 2.32.0) and the emitDecoratorMetada: true flag as I need reflect-metadata on the transpiled code. Running npm run build creates the necessary kind of metadata on the resulting js files, but when calling npm run cdk deploy or npm run cdk diff, the js file in the resulting assets does not contain the kind of metadata. According to https://docs.aws.amazon.com/cdk/v2/guide/work-with-cdk-typescript.html#typescript-local I would have assumed that the generation of the js files is basically the same in both npm usages (run build vs. run cdk xxx).

### Expected Behavior

Generate the same metadata info when CDK takes care of asset creation as when using npm run build.

### Current Behavior

Generated index.js in the asset folder of the CDK outupt doesn't contain the expected metadata.

### Reproduction Steps

Use NodejsFunction in 2.32.0 and Typescript files which use decorators and reflect-metadata, and set
bundling: {
preCompilation: true,
},

Additionally, tsconfig has to have "emitDecoratorMetadata": true

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### CDK CLI Version

2.32.0

### Framework Version

2.32.0

### Node.js Version

v18.5.0

### OS

Mac OS 13 beta 3

### Language

Typescript

### Language Version

3.9.7

### Other information

I'm using 2.32.0 as there were problems around "preCompilation" (see #18002 which this one here might be related).

Contributor guide

Open the contributing guide

Research direction

Start with NodejsFunction bundling with preCompilation enabled, the project's tsconfig emitDecoratorMetadata setting, and the npm build versus cdk diff/deploy asset-generation paths. Compare the generated index.js metadata in both outputs and trace where the compilation options diverge. Done means CDK-generated assets include the same decorator metadata as the npm build output.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, node.js, typescript
Domain
build-system, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.