Skip to content

Ladle fails to launch with react-router in "framework" mode #615

@AtiX

Description

@AtiX

Describe the bug

When the repository is using react-router in framework mode, ladle fails to serve or build:

❯ ladle serve
Error: Could not find a root route module in the app directory as "app/root.tsx"
    at createConfigLoader (/home/projects/ladle-jkx1rg7v/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/@react-router/dev/dist/vite.js:516:11)
Error: Could not find a root route module in the app directory as "app/root.tsx"
    at createConfigLoader (/home/projects/ladle-jkx1rg7v/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/@react-router/dev/dist/vite.js:516:11)

Reproduction

Reproduction example: https://stackblitz.com/edit/ladle-jkx1rg7v?file=app%2Froot.tsx - try running ladle serve

The issue seems to be that during startup vite and the reactRouter() plugin search for (1) routes and (2) the react-router.config files in the root directory. However, root is set to /Users/.../node_modules/@ladle/react/typings-for-build/app and not the actual project directory.

Code extract (vite.js):

async function createConfigLoader({
  rootDirectory: root,
  watch: watch2
}) {
// Is set to "/Users/.../node_modules/@ladle/react/typings-for-build/app"
  root = root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
  let viteNodeContext = await createContext({
    root,
    mode: watch2 ? "development" : "production"
  });
// File cannot be found
  let reactRouterConfigFile = findEntry(root, "react-router.config", {
    absolute: true
  });
  let getConfig = () => resolveConfig({ root, viteNodeContext, reactRouterConfigFile });
  let appDirectory;
  let initialConfigResult = await getConfig();
// Config is not okay, error is thrown
  if (!initialConfigResult.ok) {
    throw new Error(initialConfigResult.error);
  }
...
}

Environment

  • OS: macOS 15.4.1
  • Node 22.14

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions