Skip to content

Bug(swc): nest start --watch with swc will be initialized twice #3108

@zhangyuang

Description

@zhangyuang

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

$ nest new project-name && cd project-name && yarn
$ npx nest start --watch -b swc

The output log info is here, Nest application successfully will be output twice because process has been created twice.

SWC Running...
Successfully compiled: 5 files with swc (27.22ms)
childProcessRef null
(node:61503) [DEP0190] DeprecationWarning: Passing args to a child process with shell option true can lead to security vulnerabilities, as the arguments are not escaped, only concatenated.
(Use node --trace-deprecation ... to show where the warning was created)
Watching for file changes.
[Nest] 61509 - 2025/07/30 17:16:04 LOG [NestFactory] Starting Nest application...
[Nest] 61509 - 2025/07/30 17:16:04 LOG [InstanceLoader] AppModule dependencies initialized +3ms
[Nest] 61509 - 2025/07/30 17:16:04 LOG [RoutesResolver] AppController {/}: +1ms
[Nest] 61509 - 2025/07/30 17:16:04 LOG [RouterExplorer] Mapped {/, GET} route +1ms
[Nest] 61509 - 2025/07/30 17:16:04 LOG [NestApplication] Nest application successfully started +0ms
[Nest] 61535 - 2025/07/30 17:16:04 LOG [NestFactory] Starting Nest application...
[Nest] 61535 - 2025/07/30 17:16:04 LOG [InstanceLoader] AppModule dependencies initialized +3ms
[Nest] 61535 - 2025/07/30 17:16:04 LOG [RoutesResolver] AppController {/}: +1ms
[Nest] 61535 - 2025/07/30 17:16:04 LOG [RouterExplorer] Mapped {/, GET} route +1ms
[Nest] 61535 - 2025/07/30 17:16:04 LOG [NestApplication] Nest application successfully started +1ms

Minimum reproduction code

Use offical default example

Steps to reproduce

$ nest new project-name && cd project-name && yarn
$ npx nest start --watch -b swc

Expected behavior

I hope the NestJS application should start once.

Package version

^11.0.0

NestJS version

^11.0.0

Node.js version

24

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

The logic is here https://github.com/nestjs/nest-cli/blob/master/lib/compiler/swc/swc-compiler.ts#L60

OnSuccess will be called twice when first running. In my opinion, watchFilesInOutDir method should be executed after the first Nest start application finishes? So, we need to add childProcess as a return value in theonSucess method.

If we can reach a consensus, I'll be happy to send a pull request to fix it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions