router: after upgrade router-plugin to v1.121.22, cannot compile successfully project based on the file-based routing with Rspack or Rsbuild

Which project does this relate to?

Router

Describe the bug

before (compile successfully): @tanstack/react-router: 1.116.0 @tanstack/router-plugin: 1.116.1 @rsbuild/core: 1.1.8

after: @tanstack/react-router: 1.121.21 @tanstack/router-plugin: 1.121.22 @rsbuild/core: 1.1.8

error:

error   Compile error: 
Failed to compile, check the errors for troubleshooting.
× Error: [html-rspack-plugin]: Child compilation failed:
  │   × Module parse failed:
  │   ╰─▶   × JavaScript parsing error: Expression expected
  │          ╭─[1:0]
  │        1 │ <!DOCTYPE html>
  │          · ─
  │        2 │ <!--
  │        3 │     NOTE: This HTML file is a template. If you open it directly in the browser,
  │          ╰────
  │ 
  │   help:
  │         File was processed with these loaders:
  │          * checkoutroot/node_modules/@rsbuild/core/compiled/html-rspack-plugin/loader.js
  │          * checkoutroot/node_modules/unplugin/dist/rspack/loaders/transform.js??tanstack-router:hmr
  │         You may need an additional loader to handle the result of these loaders.

Your Example Website or App

reproduce demo

Steps to Reproduce the Bug or Issue

see description

Expected behavior

please see description

Screenshots or Videos

No response

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 91.1]

Additional context

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 2
  • Comments: 18 (8 by maintainers)

Commits related to this issue

Most upvoted comments

It’s okay, at least I’m unblocked with both a production and dev build, thanks for investigating.

Can anyone else confirm the issue? @tcdw @qiuzhangxi77

If anybody runs into this issue, this is my current fix:

import { tanstackRouter, TanStackRouterGeneratorRspack } from "@tanstack/router-plugin/rspack";

return defineConfig({
    html: {
      template: "./index.html", 
      templateParameters: { ... }
    }
    tools: {
      rspack: {
        plugins: [
          {
            ...(isProduction || isStaging ? tanstackRouter({
              routesDirectory: "./src/routes",
              enableRouteGeneration: true,
            }) : TanStackRouterGeneratorRspack({
              routesDirectory: "./src/routes",
              enableRouteGeneration: true,
            })),
          }
        ],
      }
    }
  });

@schiller-manuel

// import { tanstackRouter } from "@tanstack/router-plugin/rspack"; // broken
import { TanStackRouterGeneratorRspack } from "@tanstack/router-plugin/rspack"; // works in dev