Deployment error

Request for Support: Next.js Build Failing on Vercel Due to useSearchParams()

Issue Summary

Our Next.js 14+ project fails to build on Vercel due to an error related to useSearchParams() being used inside a server component.

Current Behavior

The deployment fails with the following error:

arduino

CopyEdit

useSearchParams() should be wrapped in a suspense boundary at page "/deckcomercial".

Similar errors occur for /404 and / (home page), causing the build to fail on Vercel.

Expected Behavior

The project should successfully build and deploy without encountering useSearchParams() errors.


:mag_right: Steps to Reproduce

  1. Using Next.js 14+, deploy a project that includes useSearchParams() inside a component.
  2. Ensure the component is located within /app/ (which defaults to a server component).
  3. Deploy on Vercel.
  4. Observe the build failure with the useSearchParams() error.

:wrench: What We Have Tried

:white_check_mark: Adding "use client"; to the component using useSearchParams().
:white_check_mark: Wrapping the component inside <Suspense>.
:white_check_mark: Moving useSearchParams() into a separate client-only component.
:white_check_mark: Ensuring no parent server components depend on the client component.
Despite these changes, the build still fails on Vercel.


:hammer_and_wrench: Project Information

  • Framework: Next.js 14.2.16
  • Hosting: Vercel
  • Environment: Production
  • Affected Routes:
    • /deckcomercial
    • /404
    • / (home page)
  • Relevant Dependencies:
    • "next": "14.2.16"
    • "react": "18.3.1"
    • "react-dom": "18.3.1"
    • "next/navigation" used for useSearchParams()

:question: Request for Help

  • What is the correct approach to handling useSearchParams() in a Next.js 14+ app on Vercel?
  • Is there an official recommendation for structuring components that require useSearchParams()?
  • How can we prevent Next.js from trying to prerender pages that rely on useSearchParams()?

:pushpin: Any guidance, best practices, or insights would be greatly appreciated! :pray::rocket:

There’s another community post with 404 debugging tips that might be helpful. Please give these solutions a try and let us know how it goes.

A human should be around soon to offer more advice. But you can also get helpful information quickly by asking v0.

1 Like

This GitHub issue has more explanation about how useSearchParams affects page rendering: useSearchParams() should not need to be wrapped in a suspense boundary · Issue #74494 · vercel/next.js · GitHub

I also recommend reviewing the v14 docs for additional info and examples: Functions: useSearchParams | Next.js

I hope that helps!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.