If using Vite with React Router or Remix, you must perform two steps to prevent build errors:
Configure SSR and Mock Next.js Navigation: Add nextstepjs and motion to noExternal in your vite.config.ts. You also need to mock next/navigation because NextStepjs may attempt to access it.
Create a Mock File: Create /src/mocks/next-navigation.ts with the following content:
export const useRouter = () => ({
push: () => {},
replace: () => {},
prefetch: () => {},
back: () => {},
forward: () => {},
refresh: () => {},
});
export const usePathname = () => '';
export const useSearchParams = () => new URLSearchParams();
export const useParams = () => ({});
- Update Vite Alias: Update
vite.config.mts to alias next/navigation to your mock file.
import path from 'node:path';
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
export default defineConfig({
ssr: {
noExternal: ['nextstepjs', 'motion'],
},
plugins: [react()],
resolve: {
alias: [
{
find: 'next/navigation',
replacement: path.join(process.cwd(), 'src/mocks/next-navigation.ts'),
},
],
},
});
export default defineConfig({
ssr: {
noExternal: ['nextstepjs', 'motion'],
},
// ... alias configuration
});