Next.js Discord

Discord Forum

Cloudinary Node SDK in Next.js 13 using App dir: dependency conflict

Unanswered
Common Poorwill posted this in #help-forum
Open in Discord
Common PoorwillOP
I get this compiler error when trying to import cloudinary in /App/api/image/route.tsx:

./node_modules/vm2/lib/compiler.js
Module not found: Can't resolve 'coffee-script' in '/Users/me/my-project/node_modules/vm2/lib


This is how the API route looks like:
import { NextRequest, NextResponse } from 'next/server'
import {v2 as cloudinary} from 'cloudinary'

const UPLOAD_IMAGE_URL = process.env.UPLOAD_IMAGE_URL

export async function POST(  req,  res) {
    try {
        const formData = req.body

        //cloudinary upload logic goes here

        return NextResponse.json({ message: 'Hello Everyone!' })

    } catch (e){
        console.log(e)
        return NextResponse.json({message: 'failed'})
    }
}

Interestingly, this error happens when using App dir only, doesn't happen in the same Next.js version using Routes directory.
Any hints very much appreciated!!!!

0 Replies