#require('node:crypto').randomUUID()

1 messages · Page 1 of 1 (latest)

quick flume
#

I'm trying to get payload to work with cacheComponents but I'm getting this error on build:

[browser] Error: Route "/players/[player]" used `require('node:crypto').randomUUID()` before accessing either uncached data (e.g. `fetch()`) or Request data (e.g. `cookies()`, `headers()`, `connection()`, and `searchParams`). Accessing random values synchronously in a Server Component requires reading one of these data sources first. Alternatively, consider moving this expression into a Client Component or Cache Component. See more info here: https://nextjs.org/docs/messages/next-prerender-random
    at Array.forEach (<anonymous>:1:22)
    at Array.forEach (<anonymous>:1:22)
    at Array.forEach (<anonymous>:1:22)
    at  collectionByWhere (src\helpers\payload\collection-by-where.ts:33:18)
    at <anonymous> (src\app\(frontend)\players\[player]\page.tsx:102:18)
    at  Module.generateMetadata (src\app\(frontend)\players\[player]\page.tsx:94:21)

I know payload is not supporting it at this moment but I'd like to try to get it working.

collectionByWhere is just a simple wrapper for payload.find:

export const collectionByWhere = async <T extends CollectionSlug>({
  collection,
  limit,
  page,
  pagination,
  where,
  select,
  depth,
  sort,
  draft,
  overrideAccess,
}: CollectionByWhere<T>) => {
  const payload = await getPayload({ config })
  const result = await payload.find({
    collection,
    where,
    page,
    limit,
    select,
    pagination,
    depth: depth ?? 1,
    sort,
    draft,
    overrideAccess,
  })

  return result
}```