Skip to content

fix(swc): fail build on type errors with type check#3319

Open
maruthang wants to merge 1 commit intonestjs:masterfrom
maruthang:fix/issue-2646-swc-type-check-exit
Open

fix(swc): fail build on type errors with type check#3319
maruthang wants to merge 1 commit intonestjs:masterfrom
maruthang:fix/issue-2646-swc-type-check-exit

Conversation

@maruthang
Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

When running nest build -b swc --type-check, type errors are detected and printed to the console, but the build process still exits with code 0 (success). This happens because process.exit(1) is called inside runOnce, which terminates the process before the error can propagate back to the caller. The spinner always shows success, and SwcCompiler.run proceeds with compilation despite type errors.

Issue Number: #2646

What is the new behavior?

Type errors now cause the build to fail properly with exit code 1. The process.exit(1) call in runOnce has been replaced with a thrown Error, which propagates naturally: runOnce throws, run catches the error and fails the spinner, the promise rejects, SwcCompiler.run skips compilation, and BuildAction.handle catches the rejection and exits with code 1.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

  • lib/compiler/swc/type-checker-host.ts: Replaced process.exit(1) with throw new Error(...) and added try/catch around runOnce to fail the spinner on error before re-throwing.
  • test/lib/compiler/swc/type-checker-host.spec.ts: Added 4 regression tests covering both success and failure paths for run and runOnce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant