Application error: a server-side exception has occurred Digest: 3693266375

45 Views Asked by At

I'm trying to deploy my website, done in NextJs14, to netlify. But I got this error when I access a specific page, which is working on dev env

export async function getImageData(galerieType: string): Promise<Photo[]> {
    const imageDirectory = ./public/photos/${galerieType};
    try {
        const imageFiles = await readdir(imageDirectory); // Utilisez la version asynchrone de fs.readdir

        const imageFilesData: Photo[] = await Promise.all(imageFiles.map(async (imageName: string) => {
            const imagePath = path.join(imageDirectory, imageName);
            const imageUrl = `/photos/${galerieType}/${imageName}`;
            const dimensions = await sizeOf(imagePath); // Attendez que sizeOf soit terminé

            return {
                id: imageName,
                width: dimensions.width || 500,
                height: dimensions.height || 500,
                src: imageUrl,
                alt: `Description de l'image ${imageName}`,
            };
        }));

        return imageFilesData;
    } catch (error) {
        console.error("Error reading image directory:", error);
        throw error; // Propagez l'erreur à l'appelant
    }
}

After a few test I've seen that the line with "readdir" is making trouble. But I cant understand how to solve it

I've commented everything else, except the readdir's line, and I'm having the problem.

0

There are 0 best solutions below