Search code examples
reactjsnext.jsbuild

Build failed due to error 'Export encountered errors on following paths: '


I am facing an error when I try to build my project locally and on Vercel. The build fails with the following error:

**the error **

Export encountered errors on following paths: /(dashboard)/dashboard/edit-resume/page: /dashboard/edit-resume error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

If I comment out the useSearchParams part, the build completes successfully.

I have also tried using Suspense like below, but it didn’t resolve the issue:

My code

The error appears to be related to useSearchParams from next/navigation. Here's the problematic code snippet:

`import { useSearchParams } from "next/navigation";

const router = useRouter();
const searchParams = useSearchParams();
const search = searchParams.get("template");
console.log("queryParams", search);
`

`return (
    <Suspense fallback={<Loader size="lg" />}>
        <div className="flex flex-col md:flex-row">
            // other codes
        </div>
    </Suspense>
);
`

I have searched stack overflow and github issues cannot find any solution, can anyone help me?

Solution

  • At last, solved the issue, I was giving the suspense in the component level but it should be at the parent of the component in my it is the loading.tsx component as I am using App router in next.js 14. Thanks all.