Skip to content

[Bug]: v7 regression in a monorepo since prerelease #12390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xalechez opened this issue Nov 25, 2024 · 6 comments · Fixed by #13472
Closed

[Bug]: v7 regression in a monorepo since prerelease #12390

xalechez opened this issue Nov 25, 2024 · 6 comments · Fixed by #13472

Comments

@xalechez
Copy link

xalechez commented Nov 25, 2024

What version of React Router are you using?

7.0.1

Steps to Reproduce

  • Create a repository with a package.json in a root
  • Install react router 7 dependencies to the package.json above
  • Create a directory like apps/test-app with vite.config.ts and react-router.config.ts specifying appDirectory
  • Run react-router build -c apps/test-app/vite.config.ts from the root of the repository

RR7 config:

import { join } from 'node:path';

import { build } from 'esbuild';

import type { Config } from '@react-router/dev/config';

export default {
  appDirectory: join(import.meta.dirname, 'app'),
  buildDirectory: join(
    import.meta.dirname,
    '../../dist/apps/test-app/static',
  ),
  serverModuleFormat: 'esm',
  ssr: true,
  buildEnd: async () => {
    await build({
      outfile: join(import.meta.dirname, '../../dist/apps/test-app/rr7.mjs'),
      entryPoints: [join(import.meta.dirname, 'rr7.mts')],
      external: [
        join(
          import.meta.dirname,
          '../../dist/apps/test-app/static/server/index.js',
        ),
      ],
      platform: 'node',
      format: 'esm',
      packages: 'external',
      bundle: true,
      logLevel: 'info',
    }).catch((error: unknown) => {
      console.error('Error building server:', error);
      process.exit(1);
    });
  },
} satisfies Config;

Expected Behavior

I would like to be able to run my application from the root of my monorepo by specifying the location of vite.config.ts like I did when I tested a pre-release version

OR

I would like to be able to run my application from apps/test-app with the package.json resolved from the root of my monorepo

Actual Behavior

Currently it works in two modes:

  • Either I run a script from the root and react-router fails with Error: Could not find a root route module in the app directory as "app/root.tsx"
  • Or I run it from the app folder and it fails to resolve package.json

This problem can be solved just by adding a package.json to the app folder, but we opted in to single version policy per monorepo as it becomes quite tedious to maintain dependencies for multiple applications at the same time. React Router 7 pre-release satisfied our needs, but as vite config and RR config are now separated, it looks like this functionality is no longer supported

@xalechez
Copy link
Author

xalechez commented Jan 6, 2025

Any progress on this one?

@andrew-canvette
Copy link

@xalechez, I had a similar error in a monorepo and I solved it by updating my vite config to set the root to the directory the config is in.

export default defineConfig({
  css: {
    postcss: {
      plugins: [tailwindcss, autoprefixer],
    },
  },
  plugins: [reactRouter(), tsconfigPaths()],
  root: __dirname,
});

@markdalgleish
Copy link
Member

markdalgleish commented Apr 28, 2025

@xalechez Thanks for raising these issues.

I've opened a PR with a fix: #13472

I've published an experimental release with the fix if you want to try it out in the meantime: 0.0.0-experimental-1d760f6a6

@markdalgleish markdalgleish linked a pull request Apr 28, 2025 that will close this issue
@markdalgleish
Copy link
Member

I've merged a fix in #13472 which will be out in the next release.

If the fix in 0.0.0-experimental-1d760f6a6 doesn't work, please let me know 🙏

Copy link
Contributor

github-actions bot commented May 8, 2025

🤖 Hello there,

We just published version 7.6.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Copy link
Contributor

🤖 Hello there,

We just published version 7.6.1 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

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

Successfully merging a pull request may close this issue.

5 participants