Next.js Discord

Discord Forum

Problem with noStore() and cloudinary

Answered
Order posted this in #help-forum
Open in Discord
Avatar
I'm making a relatively simple website that has a gallery section, the photos are stored in cloudinary, and everything works in a dev environment. However I noticed that when running npm run build && npm run start the gallery section remains static, as it prefetches the assets at build time and then if I add new photos/albums to the gallery those do not get fetched and rendered after the project's been built. So the obvious solution would be to make the route dynamic, but this has created a new issue. First here's my cloudinary.ts file that I use for configuration:
import { v2 } from "cloudinary";

if (
  !process.env.CLOUDINARY_API_KEY ||
  !process.env.CLOUDINARY_API_SECRET ||
  !process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
) {
  throw new Error("Missing Cloudinary environment variables");
}

v2.config({
  cloud_name: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME,
  api_key: process.env.CLOUDINARY_API_KEY,
  api_secret: process.env.CLOUDINARY_API_SECRET,
});

export const cloudinary = v2;


Seems ordinary enough.

Then here's the page where I'm using that cloudinary export to fetch the album names:
https://codefile.io/f/gZVaLaGlJA


The problem arises the moment i make the route dynamic using noStore() or 'use dynamic' directive, the app still builds successfully but the moment I go to the /gallery route I'm getting a 500 Internal Server error and this in my console:
TypeError: i.v2.config is not a function
    at 19577 (F:\VSCODE projects\paskalevetsinfo\.next\server\app\gallery\page.js:9:4211)
    at Function.t (F:\VSCODE projects\paskalevetsinfo\.next\server\webpack-runtime.js:1:143)


I checked to see if my .ENV file is being read properly, and it is, so I'm at a loss as to whats gone wrong.
Image
Answered by Order
turns out that using the .config() method of cloudinary expects it to be used with "require' instead of import, solution was instead of setting up custom config just to make a single CLOUDINARY_URL environment variable and it knows to use it to configure itself, weird and undocumented behavior but seems to have nothing to do with nextJS itself
View full answer

1 Reply

Avatar
turns out that using the .config() method of cloudinary expects it to be used with "require' instead of import, solution was instead of setting up custom config just to make a single CLOUDINARY_URL environment variable and it knows to use it to configure itself, weird and undocumented behavior but seems to have nothing to do with nextJS itself
Answer