Skip to content

react 3rd party lib crawling for automatic noExternal should take custom root into account #1126

Description

@vixalien

Related plugins

Describe the bug

The plugin resolves framework dependencies from the process.cwd() instead of checking the config.root: https://vite.dev/config/shared-options#root

The potential fix would be to change the following line to config.root ?? process.cwd()

Reproduction

https://github.com/vixalien/repro-react-router-rsc-runner

Steps to reproduce

  1. Create an RSC app with the command: npx create-react-router@latest --template remix-run/react-router-templates/unstable_rsc-framework-mode
  2. In another folder/package create a simple JS file that uses the Vite JS API to run the RSC app by pointing vite to the previous directory
import { createServer } from "vite";                                                                                                                                                                          
                                                                                                                                                                                                              
const server = await createServer({                                                                                                                                                                           
  root: "../app",                                                                                                                                                                                             
});                                                                                                                                                                                                           
await server.listen();                                                                                                                                                                                        
                                                                                                                                                                                                              
server.printUrls();                                                                                                                                                                                           
server.bindCLIShortcuts({ print: true });                                                                                                                                                                     

System Info

System:
    OS: Linux 6.18 GNOME OS Nightly
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
    Memory: 19.50 GB / 30.64 GB
    Container: Yes
    Shell: 5.3.9 - /bin/bash
  Binaries:
    Node: 25.6.1 - /home/alien/.local/share/mise/installs/node/25.6.1/bin/node
    Yarn: 4.12.0 - /home/alien/.local/share/mise/installs/yarn/4.12.0/bin/yarn
    npm: 11.9.0 - /home/alien/.local/share/mise/installs/node/25.6.1/bin/npm
    pnpm: 10.30.1 - /home/alien/.local/share/mise/installs/pnpm/10.30.1/pnpm
    Deno: 2.6.10 - /home/alien/.local/share/mise/installs/deno/2.6.10/bin/deno

Used Package Manager

pnpm

Logs

No response

Validations

Activity

  1. added theissue type on Mar 1, 2026
  2. hi-ogawa commented on Mar 2, 2026

    @hi-ogawa
    Contributor

    Thanks for the issue. I think root: config.root ?? process.cwd() should be a way to go.

  3. vixalien commented on Mar 2, 2026

    @vixalien
    Author

    Yeah, I've tested it and it works, I can create a PR

  4. hi-ogawa commented on Mar 2, 2026

    @hi-ogawa
    Contributor

    @vixalien Please go ahead. Thank you!

  5. hi-ogawa commented on Mar 3, 2026

    @hi-ogawa
    Contributor

    Btw, crawlFrameworkPkgs is only a heuristic helper and the equivalent can be achieved by manually configuring noExternal by

    environments: {
      rsc: {
        resolve: {
          noExternal: ["react-rotuer", ...(and other react 3rd party lib)...],
        }
      },
      ssr: {
        resolve: {
          noExternal: ["react-rotuer", ...(and other react 3rd party lib)...],
        }
      },
    }
  6. hi-ogawa commented on Mar 3, 2026

    @hi-ogawa
    Contributor

    Please create rsc plugin only reproduction. The issue you are seeing seems different from rsc plugin's crawlFrameworkPkgs logic and it looks like more on react-router side.

  7. changed the title [-]RSC plugin doesn't respect the vite root, always uses `process.cwd()`[/-] [+]react 3rd party lib crawling for automatic `noExternal` should also take `config.root` into account?[/+] on Mar 3, 2026
  8. changed the title [-]react 3rd party lib crawling for automatic `noExternal` should also take `config.root` into account?[/-] [+]react 3rd party lib crawling for automatic `noExternal` should also take `config.root` into account[/+] on Mar 3, 2026
  9. changed the title [-]react 3rd party lib crawling for automatic `noExternal` should also take `config.root` into account[/-] [+]react 3rd party lib crawling for automatic `noExternal` should take custom `root` into account[/+] on Mar 3, 2026
  10. Wroud commented on Nov 26, 2026

    @Wroud

    An rsc-plugin-only reproduction, without a framework: the plugin-rsc starter (@vitejs/plugin-rsc@0.5.39, vite@8.4.0) in an npm workspace, with src/client.tsx using a zustand store:

    'use client'
    
    import { create } from 'zustand'
    
    const useCounter = create<{ count: number; increment: () => void }>((set) => ({
      count: 0,
      increment: () => set((state) => ({ count: state.count + 1 })),
    }))
    
    export function ClientCounter() {
      const { count, increment } = useCounter()
      return <button onClick={increment}>Client Counter: {count}</button>
    }
    repo/
      package.json        { "workspaces": ["app"] }
      dev.mjs             await (await createServer({ root: 'app' })).listen()
      app/package.json    react, react-dom, zustand, @vitejs/plugin-rsc, vite
    
    • vite inside app/ renders the page.
    • node dev.mjs from repo/ returns 500 with Invalid hook call / Cannot read properties of null (reading 'useCallback'). zustand is missing from environments.ssr.resolve.noExternal, so it is externalized and loads a second React next to the optimized one.

    #1585 crawls from both process.cwd() and config.root, as suggested in #1133, with unit tests for both directions. With it, both commands render.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions