I'm getting this weird error: Cannot read properties of undefined (reading 'node')
I'm using cloudinary nodejs api in a next.js 14 server actions. It has been working perfectly until recently.
When I remove cloudinary from the project, it works perfectly, whenever i add it, i get this error "TypeError: Cannot read properties of undefined (reading 'node')".
Please advise
Answers
-
Hi @Lollykrown ,
The error is likely occurring because the Cloudinary library is trying to access a Node.js environment, but Next.js 14 with Server Actions runs in a different environment called the Edge Runtime.
Could you share the code that throws this error?
I have checked this type of error and I found the following question in Stackoverflow:
Best Regards,
Wissam
0 -
'use server'
import { v2 as cloudinary } from 'cloudinary'; //deleting this line stops the error
import { randomString } from '@/utils/misc';
import pLimit from 'p-limit';
const limit = pLimit(5)
if (!process.env.CLOUDINARY_CLOUD_NAME) { throw new Error('CLOUDINARY_CLOUD_NAME is not set');}
if (!process.env.CLOUDINARY_API_KEY) { throw new Error('CLOUDINARY_API_KEY is not set');}
if (!process.env.CLOUDINARY_API_SECRET) { throw new Error('CLOUDINARY_API_SECRET is not set');}
cloudinary.config({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET,
});
export async function uploadBuffer(image) {
const imageData = await image.arrayBuffer();
const mime = image.type; const encoding = 'base64';
const base64Data = Buffer.from(imageData).toString('base64');
const fileUri = 'data:' + mime + ';' + encoding + ',' + base64Data; const result = await cloudinary.uploader.upload(fileUri, {
folder: 'tiviTea folder',
public_id: `tiviTea-${randomString(10)}`,
});
return result.secure_url;
}
export async function bulkUploadBuffer(images) {
const res = images.map(image =>{
return limit(async() => {
const imageData = await image.arrayBuffer();
const mime = image.type;
const encoding = 'base64';
const base64Data = Buffer.from(imageData).toString('base64');
const fileUri = 'data:' + mime + ';' + encoding + ',' + base64Data;
const result = await cloudinary.uploader.upload(fileUri,{
folder: 'tiviTea folder',
public_id: `tiviTea-${randomString(10)}`,
return result.secure_url;
})
})
let uploads = await Promise.all(res) return uploads;
}
0 -
Did you find a fix? Im getting the same error when using sdk in Cloudflare workers
0 -
No. I had to find another way
0 -
Another way as in: fetching the api directly?
0