Skip to content

Webpack: router-code-splitter plugin calls process.exit(0) on done in production, terminating the process prematurely #5069

@Pavel-Liteiniy

Description

@Pavel-Liteiniy

Which project does this relate to?

Router

Describe the bug

Summary
The webpack integration of @tanstack/router-plugin’s code-splitter calls process.exit(0) on compiler.hooks.done in production mode. This forcibly ends the Node.js process and can interrupt other plugins’ post-build work (async tasks scheduled in done or afterEmit), and breaks long-running workflows (e.g. production watch).

node_modules/@tanstack/router-plugin/dist/cjs/core/router-code-splitter-plugin.cjs:

if (compiler.options.mode === "production") {
  compiler.hooks.done.tap(PLUGIN_NAME, () => {
    console.info("✅ " + PLUGIN_NAME + ": code-splitting done!");
    setTimeout(() => {
      process.exit(0);
    });
  });
}

Your Example Website or App

none

Steps to Reproduce the Bug or Issue

  1. Configure webpack in production mode with @tanstack/router-plugin/webpack.
  2. Add any plugin that performs async work after build completion (e.g. a plugin that schedules a setTimeout, uploads artifacts, or writes additional reports in done/afterEmit).
  3. Run a production build.

Expected behavior

  • Webpack process remains alive until the event loop drains, allowing other plugins’ async post-build tasks to finish.
  • If watch is enabled in production, it should keep watching.

Screenshots or Videos

No response

Platform

  • Router Version: 1.132.0-alpha.13
  • Bundler: Webpack
  • Bundler Version: 5.91.0

Additional context

https://github.com/TanStack/router/blob/main/packages/router-plugin/src/core/router-code-splitter-plugin.ts#L245

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions