Skip to content

nitro/vite will break down unocss in tanstack start RC #3596

Closed

Description

@zouhangwithsweet

Environment

  • nitro: 3.0.0-20250925-181710-5191890e
  • nodejs: v24.5.0

Reproduction

https://github.com/fisand/f3-app/tree/main/apps/web-tanstack

Describe the bug

If I use nitro/vite to build a tanstack start(RC) APP, it looks like will remove vite:css-post plugin, then the CSS will not generator succefully.

[plugin unocss:global:build:generate] [unocss] failed to find vite:css-post plugin. It might be an internal bug of UnoCSS

Other issue is nitro/vite will not match a 404 route to noFoundComponent in a tanstack start(RC) APP, it will always loading util the APP crash.

node:internal/deps/undici/undici:13484
      Error.captureStackTrace(err);
            ^

TypeError: fetch failed
    at node:internal/deps/undici/undici:13484:13

  [cause]: HeadersTimeoutError: Headers Timeout Error
      at FastTimer.onParserTimeout [as _onTimeout] (/node_modules/.pnpm/[email protected]/node_modules/undici/lib/dispatcher/client-h1.js:757:28)
      at Timeout.onTick [as _onTimeout] (/Users/SYY/Desktop/work/f3-app/node_modules/.pnpm/[email protected]/node_modules/undici/lib/util/timers.js:162:13)
      at listOnTimeout (node:internal/timers:594:17)
      at process.processTimers (node:internal/timers:529:7) {
    code: 'UND_ERR_HEADERS_TIMEOUT'
  }

Additional context

No response

Logs

Activity

  1. added
    pending triage
    on Sep 28, 2025
  2. changed the title [-]`nitro/vite` will break down unocss in tanstack RC[/-] [+]`nitro/vite` will break down unocss in `tanstack start RC`[/+] on Sep 28, 2025
  3. added
    needs reproduction
    on Sep 28, 2025
  4. pi0 commented on Sep 28, 2025

    @pi0
    Member

    Can you please share a minimal reproduction with nitro plugin only + unocss? (no tanstack start)

  5. added
    vite
    on Sep 28, 2025
  6. zouhangwithsweet commented on Oct 9, 2025

    @zouhangwithsweet
    Author

    Sorry I cannot make a reproduction successfully. But I think it has a relation with these codes:

    https://github.com/unocss/unocss/blob/main/packages-integrations/vite/src/modes/global/build.ts#L127

    async configResolved(config) {
            const distDirs = [
              resolve(config.root, config.build.outDir),
            ]
    
            // for Vite lib more with rollupOptions.output, #2231
            if (config.build.rollupOptions.output) {
              const outputOptions = config.build.rollupOptions.output
              const outputDirs = Array.isArray(outputOptions)
                ? outputOptions.map(option => option.dir).filter(Boolean) as string[]
                : outputOptions.dir
                  ? [outputOptions.dir]
                  : []
    
              outputDirs.forEach((dir) => {
                distDirs.push(dir)
    
                if (!isAbsolute(dir))
                  distDirs.push(resolve(config.root, dir))
              })
            }
    
            const cssPostPlugin = config.plugins.find(i => i.name === 'vite:css-post') as Plugin | undefined
            const cssPlugin = config.plugins.find(i => i.name === 'vite:css') as Plugin | undefined
    
            if (cssPostPlugin)
              distDirs.forEach(dir => cssPostPlugins.set(dir, cssPostPlugin))
    
            if (cssPlugin)
              distDirs.forEach(dir => cssPlugins.set(dir, cssPlugin))
    
            await ready
          },

    nitro/vite use a custom viteserver to build file, but the unocss just read the user's vite.config. So when it scan the file, it will not find the right path.

    https://github.com/nitrojs/nitro/blob/main/src/build/vite/build.ts#L10

    const builder = await createBuilder({
        base: nitro.options.rootDir,
        plugins: [nitroPlugin({ _nitro: nitro })],
      });
  7. zouhangwithsweet commented on Oct 9, 2025

    @zouhangwithsweet
    Author

    So to fix it issue the easy way is that we can let unocss/vite know nitro output path. Just add the build.outdir filed. But I will not effect the nitro.

    Image
  8. zouhangwithsweet commented on Oct 9, 2025

    @zouhangwithsweet
    Author

    But I think it's a problem about nitro working with all other vite plugins. When we use nitro/vite, the development servert & the builder is not using a same config. What do you think about that ? @pi0

  9. pi0 commented on Oct 9, 2025

    @pi0
    Member

    Maybe we default userConfig.build.outDir when not set by users?

  10. zouhangwithsweet commented on Oct 10, 2025

    @zouhangwithsweet
    Author

    We can explicitly point out the differences in configuration between nitro/vite and other Vite plugins in the document to help users understand. Currently, considering that this will not affect the core functions of nitro, it is recommended that no changes be made for the time being.

  11. zouhangwithsweet commented on Oct 10, 2025

    @zouhangwithsweet
    Author

    I also notice that nitro/vite have differrent behavoir with vite or rolldown/vite

  12. gxres042 commented on Oct 10, 2025

    @gxres042
    Member

    I also notice that nitro/vite have differrent behavoir with vite or rolldown/vite

    nitro/vite hadn't supported rolldown-vite yet

  13. zouhangwithsweet commented on Nov 11, 2025

    @zouhangwithsweet
    Author

    [email protected] will break dev server down with tanstack start.

    node:internal/url:826
          href = bindingUrl.parse(input, base, true);
                            ^
    
    TypeError: Invalid URL
        at new URL (node:internal/url:826:25)
  14. pi0 commented on Nov 11, 2025

    @pi0
    Member

    I have added a fix to [email protected] to this issue. You can update lockfile to get fix.

    (keeping issue open, we should fix some more places in nitro to avoid similar issues in the future)

  15. zouhangwithsweet commented on Nov 12, 2025

    @zouhangwithsweet
    Author

    nitro build will copy node_modules into server folder, but the packages's lost many files. Like drizzle-orm, it losts index.js balabla.

    --- update ---
    I can fix it with the options noExternals: true, but nitro default value is false

  16. pi0 commented on Nov 12, 2025

    @pi0
    Member

    @zouhangwithsweet only used files will be traced. Did you get a runtime error for drizzle usage? (if yes it is a bug with nf3 integration)

  17. zouhangwithsweet commented on Nov 12, 2025

    @zouhangwithsweet
    Author

    @zouhangwithsweet only used files will be traced. Did you get a runtime error for drizzle usage? (if yes it is a bug with nf3 integration)

    Yes, there is a runtime error.cannot resolve drizzel-orm/index.js. Look likes a upstream bug.

  18. zouhangwithsweet commented on Nov 12, 2025

    @zouhangwithsweet
    Author
  19. tommy141x commented on Dec 26, 2025

    @tommy141x

    I made this patch with Bun's patch system as a workaround to register Nitro v3's output directories with UnoCSS's CSS pipeline.

    diff --git a/dist/index.mjs b/dist/index.mjs
    index 6c0e0026dbda2bda499b3011864b4dd0a2f7dae8..f506d74bdbe34209ee0a1bbe9a52ba998cd3ae28 100644
    --- a/dist/index.mjs
    +++ b/dist/index.mjs
    @@ -574,6 +574,15 @@ function GlobalModeBuildPlugin(ctx) {
     				const cssPlugin = config.plugins.find((i) => i.name === "vite:css");
     				if (cssPostPlugin) distDirs.forEach((dir) => cssPostPlugins.set(dir, cssPostPlugin));
     				if (cssPlugin) distDirs.forEach((dir) => cssPlugins.set(dir, cssPlugin));
    +				// Nitro v3 compatibility: Add Nitro's output directories to CSS plugin maps
    +				if (cssPostPlugin) {
    +					cssPostPlugins.set(resolve(config.root, '.output/public'), cssPostPlugin);
    +					cssPostPlugins.set(resolve(config.root, 'node_modules/.nitro/vite/services/ssr'), cssPostPlugin);
    +				}
    +				if (cssPlugin) {
    +					cssPlugins.set(resolve(config.root, '.output/public'), cssPlugin);
    +					cssPlugins.set(resolve(config.root, 'node_modules/.nitro/vite/services/ssr'), cssPlugin);
    +				}
     				await ready;
     			}
     		},
    

    Basically patched @unocss/[email protected]/dist/index.mjs and added Nitro's .output/public and node_modules/.nitro/vite/services/ssr directories to the CSS plugin maps alongside the existing distDirs.

  20. added
    bug
    tanstack
    and removed
    pending triage
    on Sep 2, 2026
  21. pi0x commented on Sep 7, 2026

    @pi0x
    Contributor

    Root cause confirmed: Nitro sets build.outDir per Vite environment, so the top-level config that other plugins read in configResolved still says dist while the client build writes to .output/public — UnoCSS therefore never sees Nitro's output.

    Until Nitro sets a root-level default, adding build: { outDir: ".output/public" } to vite.config.ts works around it without patching UnoCSS: the client build already writes there, so nothing actually moves. Note this only covers the client build; the SSR service builds into node_modules/.nitro/vite/services/ssr, which no single root-level value can cover.

    Posted by an AI triage agent on behalf of a maintainer.

  22. added theissue type on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds reproductiontanstackvite

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions