swc
swc copied to clipboard
`NestJS` application initialised twice with `SWC`
Describe the bug
Application initializes twice when using SWC with NestJS nest start --watch (npm run start:dev in the repo's scripts), even though with nest start (npm run start in the repos' scripts) it works fine, without unnecessary re-initialize
I've upload the whole code to the repository (with README.md) where you can reproduce this bug:
https://github.com/lintellme99/nestjs-swc-bug
Input code
No response
Config
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true,
"dynamicImport": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"baseUrl": "./src"
}
}
Playground link (or link to the minimal reproduction)
https://github.com/lintellme99/nestjs-swc-bug
SWC Info output
Operating System: Platform: darwin Arch: arm64 Machine Type: arm64 Version: Darwin Kernel Version 23.1.0: Mon Oct 9 21:32:11 PDT 2023; root:xnu-10002.41.9~7/RELEASE_ARM64_T6030 CPU: (12 cores) Models: Apple M3 Pro
Binaries:
Node: 20.7.0
npm: 10.1.0
Yarn: N/A
pnpm: N/A
Relevant Packages:
@swc/core: 1.7.6
@swc/helpers: N/A
@swc/types: 0.1.12
typescript: 5.5.4
SWC Config:
output: N/A
.swcrc path: N/A
Next.js info:
output: N/A
Expected behavior
NestJS nest start --watch command executes only one initializition of main.ts file and bootstrap function
Actual behavior
NestJS nest start --watch command executes two initializitions of main.ts file and bootstrap function
Version
"@swc/cli": "0.4.0", "@swc/core": "1.7.6"
Additional context
No response
An interesting fact is that if you add a few more files that swc will have to process (I just cloned all files 6 times with different names), then the bug will disappear
As soon as I had 38 files Successfully compiled: 38 files with swc (37.96ms) instead of the 6 with which the bug is playing, it stopped reproducing:
TSC Initializing type checker...[Nest] 24965 - 08/05/2024, 5:37:05 PM LOG [NestFactory] Starting Nest application...
[Nest] 24965 - 08/05/2024, 5:37:05 PM LOG [InstanceLoader] KyselyModule dependencies initialized +6ms
[Nest] 24965 - 08/05/2024, 5:37:05 PM LOG [InstanceLoader] ConfigHostModule dependencies initialized +0ms
[Nest] 24965 - 08/05/2024, 5:37:05 PM LOG [InstanceLoader] AppModule dependencies initialized +0ms
[Nest] 24965 - 08/05/2024, 5:37:05 PM LOG [InstanceLoader] LoggerModule dependencies initialized +1ms
[Nest] 24965 - 08/05/2024, 5:37:05 PM LOG [InstanceLoader] ConfigModule dependencies initialized +0ms
[Nest] 24965 - 08/05/2024, 5:37:05 PM LOG [InstanceLoader] ConfigModule dependencies initialized +0ms
[Nest] 24965 - 08/05/2024, 5:37:05 PM LOG [InstanceLoader] KyselyCoreModule dependencies initialized +0ms
[Nest] 24965 - 08/05/2024, 5:37:05 PM LOG [RoutesResolver] AppController {/}: +3ms
[Nest] 24965 - 08/05/2024, 5:37:05 PM LOG [RouterExplorer] Mapped {/, GET} route +1ms
[Nest] 24965 - 08/05/2024, 5:37:05 PM LOG [NestApplication] Nest application successfully started +1ms
✔ TSC Initializing type checker...
> TSC Found 0 issues.
@kdy1, do you know what the problem might be? I would love to help with this investigation, because I don't understand what's wrong here.
@kdy1 I have "fixed" that bug in this branch: https://github.com/lintellme99/nestjs-swc-bug/tree/without_bug
Now it works fine, but, I want it also work correctly on a small projects, that has a less than 30 files that swc should handle
Nice find @lintellme99 - @kdy1 I know you must be super busy, but let me know if you need any help getting this in!
It's not a bug of SWC. Also, please provide a SWC repro, not nestjs repro
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.