aws / aws/aws-cdk

(aws-lambda-nodejs): allow comments in tsconfig.json

Open
#18,974 2 comments 2 reactions 0 assignees View on GitHub
@aws-cdk/aws-lambda-nodejs effort/small feature-request p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### What is the problem?

tsconfig.json can have comments in it, as explained here: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-1-8.html#allow-comments-in-tsconfigjson

But the aws-lambda-nodejs will try to load tsconfig and it fails because of comments.

### Reproduction Steps

construct:
```ts
new lambda.NodejsFunction(this, 'put-records', {
bundling: {
preCompilation: true,
},
});
```

tsconfig.json:
```ts
{
"compilerOptions": {
// some comment
"lib": ["es2019", "es2020.promise", "es2020.bigint", "es2020.string"],
"module": "commonjs",
"target": "es2019",

"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}
```

### What did you expect to happen?

The function to be compiled.

### What actually happened?

```
SyntaxError: /redacted/tsconfig.json: Unexpected token / in JSON at position 597
at parse ()
at Object.Module._extensions..json (internal/modules/cjs/loader.js:1115:22)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at extractTsConfig (/redacted/node_modules/aws-cdk-lib/aws-lambda-nodejs/lib/util.ts:196:56)
at Object.getTsconfigCompilerOptions (/redacted/node_modules/aws-cdk-lib/aws-lambda-nodejs/lib/util.ts:149:27)
at Bundling.createBundlingCommand (/redacted/node_modules/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts:162:31)
at new Bundling (/redacted/node_modules/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts:133:34)
```

### CDK CLI Version

2.12.0

### Framework Version

_No response_

### Node.js Version

14.17.6

### OS

macOs 12.2

### Language

Typescript

### Language Version

4.5.2

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Read aws-lambda-nodejs/lib/util.ts, especially extractTsConfig and getTsconfigCompilerOptions, then reproduce the failure with the issue's NodejsFunction and commented tsconfig.json. Done means the same construct accepts comments in tsconfig.json and compiles successfully without the JSON syntax error.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, 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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.