Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lambda-nodejs: NodejsFunction not ignoring noEmit in tsconfig when pre-compiling #25603

Closed
leestkly opened this issue May 15, 2023 · 4 comments · Fixed by #25604
Closed

lambda-nodejs: NodejsFunction not ignoring noEmit in tsconfig when pre-compiling #25603

leestkly opened this issue May 15, 2023 · 4 comments · Fixed by #25604
Labels
@aws-cdk/aws-lambda-nodejs bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@leestkly
Copy link
Contributor

Describe the bug

When using the preCompilation: true bundling option to NodejsFunction with a tsconfig that contains the compiler option "noEmit": true, no compiled .js files are generated by the pre-compilation step before bundling. This may cause esbuild to bundle the original .ts files instead, which is not the intended outcome when using pre-compilation.

Some projects may enable noEmit in their tsconfig so that they can use tsc to perform type checking without generating needless output files, since NodejsFunction will do that automatically as part of pre-compilation during deployment.

When NodejsFunction builds the tsc options from the tsconfig for pre-compilation, it should ignore any noEmit compiler option so that output files will always be generated.

Expected Behavior

A setting of "noEmit": true in tsconfig has no effect on the pre-compilation behavior of NodejsFunction. Pre-compilation will still output the compiled .js files before bundling.

Current Behavior

A setting of "noEmit": true in tsconfig prevents the pre-compilation option of NodejsFunction from working correctly, as no .js files are generated. In this case, esbuild bundles the original .ts files, which is not the desired outcome.

Reproduction Steps

Using a tsconfig.json such as:

{
  "compilerOptions": {
    "target": "es2021",
    "module": "commonjs",
    "lib": [
      "es2021",
      "dom"
    ],
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "esModuleInterop": true,
    "isolatedModules": true,
    "strict": true,
    "allowUnusedLabels": false,
    "noEmit": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitOverride": true,
    "noImplicitReturns": true,
    "typeRoots": [
      "./node_modules/@types"
    ]
  },
  "exclude": [
    "node_modules",
    "cdk.out"
  ]
}

with a NodejsFunction such as:

new NodejsFunction(this, 'some-function', {
    bundling: {
        preCompilation: true,
    },
})

will show this issue, where no pre-compiled .js files are generated.

Possible Solution

Add 'noEmit' to the excludedCompilerOptions in the getTsconfigCompilerOptions() utility function.

Additional Information/Context

No response

CDK CLI Version

2.79.1 (build 2e7f8b7)

Framework Version

No response

Node.js Version

v18.16.0

OS

macOS 12.6.5

Language

Typescript

Language Version

Typescript (5.0.4)

Other information

No response

@leestkly leestkly added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 15, 2023
@pahud
Copy link
Contributor

pahud commented May 16, 2023

Thank you for your report. We appreciate your time and PR and would be happy to review it when it's ready.

@pahud pahud added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels May 16, 2023
@mergify mergify bot closed this as completed in #25604 Jun 5, 2023
mergify bot pushed a commit that referenced this issue Jun 5, 2023
)

When building the options to `tsc` for pre-compilation from tsconfig, exclude any `noEmit` compiler option in case it has been set to `true`, which would prevent generation of the compiled .js files. Added `'noEmit'` to the list of excluded options when processing tsconfig.

Closes #25603.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Jun 5, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@RLMarkStrudwick
Copy link

RLMarkStrudwick commented Jul 4, 2023

Hello @pahud and @leestkly , this still appears to be an issue, even though the release notes mention that this was fixed in V2.83.0.
image

We are currently using V2.85.0 and have also tried V2.68.0, with noEmit and setting the outDir, but the build step is ignoring both of these TSConfig options. Please can this issue be reopened, thanks.

@alex-restless
Copy link

alex-restless commented Jul 31, 2023

Yes having the same issue at the moment

npm list

(project info redacted)
── @types/node@20.4.5
├── aws-cdk-lib@2.89.0
├── aws-cdk@2.89.0
├── dotenv@16.0.1
├── esbuild@0.18.17
├── jest@29.6.2
├── joi@17.9.2
└── ts-jest@29.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda-nodejs bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants