Next.js Discord

Discord Forum

Failed to collect page data for /endpoint

Answered
Mugger Crocodile posted this in #help-forum
Open in Discord
Mugger CrocodileOP
Hi folks. I'm getting a frustrating error I cannot interpret. In vercel an endpoint fails to build with the message "Failed to collect page data". I'm not getting this error in local build.

The error depends on the presence of any line making reference to my MinIO lib module, a service similar to S3.

myProject/src/data/bucket/minio.ts
import * as Minio from 'minio';

const minioClient = new Minio.Client({
  endPoint: process.env.MINIO_ENDPOINT!,
  port: 9000,
  useSSL: true,
  accessKey: 'dev',
  secretKey: process.env.MINIO_SECRET_KEY!,
})

const metadata = {...}

export const upload = (name: string, content: Buffer) => minioClient.putObject('myBucket', nombre, content, name)


src/app/imageStorage/route.ts
import { NextRequest, NextResponse } from "next/server"
import { upload } from "@/data/bucket/minio"

export async function POST(request: NextRequest) {
  const data = await request.formData()
  const files: File[] | null = data.getAll('files') as unknown as File[]
  await Promise.all(files.map(e => upload(e.name, Buffer.from(await e.arrayBuffer())))) // <-- THIS LINE, comment it out and the error goes away
}


I reckon this code should go in a serverless function and not directly in the frontend since
1 - it includes a secret key
2 - Minio uses the fs module
3 - it works just fine in dev, uploading the image, retreiving it afterwards and whatnot

Any help or suggestions for troubleshooting will be more than welcome

Thanks!
Answered by Mugger Crocodile
Of course not. I was missing my env variables which I sworn were there.
View full answer

5 Replies

Mugger CrocodileOP
Sadly, not progress has been made. This difference between vercel and local builds is frustrating and really hard to debug.
Mugger CrocodileOP
I tried to delay the minio client definition like so:

myProject/src/data/bucket/minio.ts
let minioClient: Minio.Client
const client = () => {
  if (minioClient === undefined) {
    minioClient = new Minio.Client({
      endPoint: process.env.MINIO_ENDPOINT!,
      port: 9000,
      useSSL: true,
      accessKey: 'dev',
      secretKey: process.env.MINIO_SECRET_KEY!,
    })
  }
  return minioClient
}

export const upload = (name: string, content: Buffer) => client().putObject('myBucket', nombre, content, name)


This allowed for the project to build nicely but I ended up with the same error in the logs 😦
The error is raised precisely upon invoking the client() function.
Is vercel preventing users from leveraging open source tools in orden for us to use paid services? 🤔
Mugger CrocodileOP
Of course not. I was missing my env variables which I sworn were there.
Answer
Mugger CrocodileOP
Still, the error message is awful