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

aviod compilation with swc + type-checking when there are type errors #2646

Open
1 task done
aberonni opened this issue Jul 9, 2024 · 5 comments
Open
1 task done

Comments

@aberonni
Copy link

aberonni commented Jul 9, 2024

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

When using SWC with NestJS, there is a handy type checking functionality. When there is a type error, you see a log in the console, but the project still compiles successfully.

I originally opened this as a bug, but I have been told this was expected behaviour: nestjs/nest#13760 so I thought it would be a good idea to report this as a feature request instead. You can see a full log example in that issue.

Describe the solution you'd like

When the type check flag is used and there is a type error, the SWC compiler does not compile the project nor show the "Application successfully started" message.

(AFAIK this would be the same behaviour as the compiler without SWC)

This should probably be configured through a new flag/configuration variable to avoid breaking changes for people already using the type check flag.

Teachability, documentation, adoption, migration strategy

For example:

Type checking

SWC does not perform any type checking itself (as opposed to the default TypeScript compiler), so to turn it on, you need to use the --type-check flag:

$ nest start -b swc --type-check

If you wish for compilation to fail when using type checking, then you can use the --type-check-fail flag

$ nest start -b swc --type-check-fail

What is the motivation / use case for changing the behavior?

This was the behaviour when using the non-SWC compiler. We got used to relying on the NestJS compilation output log to determine whether we were introducing TS errors and to safeguard us against them.

@kamilmysliwiec
Copy link
Member

What's the reason for using SWC instead of tsc if you want to wait for type-checking to complete?

@aberonni
Copy link
Author

We switched from the default compiler to SWC because of speed.

With the default compiler, it got to a point where it took ~2 minutes (on fast machines) to compile the project. With SWC it takes ~2 seconds. On the same project, npx tsc --noEmit takes ~10 seconds.

So (we assumed) something else beyond tsc is slowing down the default compiler and switching to SWC seemed the better approach for our use case, rather than investigating alternative ways to speed things up. But, after a few weeks, we noticed we lost the functionality of type checking being a safeguard during compilation.

@kamilmysliwiec kamilmysliwiec transferred this issue from nestjs/nest Jul 11, 2024
@joh9347
Copy link

joh9347 commented Jan 3, 2025

@aberonni We are also using SWC with type checking enabled, and we noticed that live-reload (nest start --watch) happens twice when type checking is enabled. I believe this might be caused by the autogenerated metadata.ts file when type checking is enabled with SWC. How did you guys work around this problem?

@aberonni
Copy link
Author

aberonni commented Jan 3, 2025

I believe this might be caused by the autogenerated metadata.ts file when type checking is enabled with SWC.

I'm not sure we have that metadata.ts file being autogenerated, but tbh I haven't looked into our setup in a while. AFAIK we don't have the double compilation issue.

@joh9347
Copy link

joh9347 commented Jan 3, 2025

@aberonni Hmm that's interesting. The Nest.js will generate metadata file automatically when type check is enabled with SWC: https://docs.nestjs.com/recipes/swc#cli-plugins-swc

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

No branches or pull requests

3 participants