build error: coffee-script module not found

Options
gmzi
gmzi Member Posts: 3

Hi all, I'm getting this build error:

"./node_modules/vm2/lib/compiler.js

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

I'm trying to use the Node SDK in a Next.js 13 Api route, intending to upload an image, the Api route looks like this:

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'})

    }

}

Answers

  • Cloudinary Team
    Cloudinary Team Administrator, Cloudinary Staff Posts: 123 admin
    Options

    Hey,

    The error you're encountering seems to be related to a missing module called 'coffee-script' in the 'vm2' package. Here are a few steps you can try to resolve the issue:

    1. Make sure you have the latest version of Node.js installed. You can check your current Node.js version by running node -v in your terminal. If you have an outdated version, consider upgrading to the latest stable release.

    2. Delete the node_modules folder in your project directory and reinstall the dependencies. This can be done by running the following commands in your terminal:

      rm -rf node_modules
      npm install
      
    3. If the issue persists after reinstalling the dependencies, it's possible that the 'vm2' package has a dependency conflict. You can try updating the 'vm2' package explicitly to a specific version. In your terminal, run:

      npm install vm2@latest
      

      This will install the latest version of the 'vm2' package.

    4. If the above steps don't resolve the issue, it's possible that the 'cloudinary' package itself has a dependency conflict with 'vm2'. In that case, you can try to force a specific version of 'vm2' that is known to work with 'cloudinary'. For example, you can install 'vm2' version 3.7.0 by running:

      npm install vm2@3.7.0
      

      Then, try running your application again and see if the error persists.

    If none of these steps help, please provide the specific versions of the 'cloudinary' and 'vm2' packages you're using, as well as any additional error messages or stack traces you receive. This information can help further investigate and assist you in resolving the issue.

  • gmzi
    gmzi Member Posts: 3
    Options

    Thanks for your response. Just tried all the steps above, but the issue persists, here are the specific versions I'm running:

    "cloudinary": "^1.37.1",

    "vm2": "^3.7.0"

    "next": "13.4.2",

    "typescript": "5.0.4",

    And here's the error message when trying to compile:

    ./node_modules/degenerator/node_modules/vm2/lib/compiler.js
    Module not found: Can't resolve 'coffee-script' in '/Users/me/my-project/node_modules/degenerator/node_modules/vm2/lib'
    
    Import trace for requested module:
    ./node_modules/degenerator/node_modules/vm2/lib/compiler.js
    ./node_modules/degenerator/node_modules/vm2/lib/script.js
    ./node_modules/degenerator/node_modules/vm2/lib/main.js
    ./node_modules/degenerator/node_modules/vm2/index.js
    ./node_modules/degenerator/dist/src/index.js
    ./node_modules/pac-resolver/dist/index.js
    ./node_modules/pac-proxy-agent/dist/agent.js
    ./node_modules/pac-proxy-agent/dist/index.js
    ./node_modules/proxy-agent/index.js
    ./node_modules/cloudinary/lib/utils/index.js
    ./node_modules/cloudinary/lib/utils/srcsetUtils.js
    ./node_modules/cloudinary/lib/cloudinary.js
    ./node_modules/cloudinary/cloudinary.js
    ./app/api/image/route.tsx
    
    ./node_modules/degenerator/node_modules/vm2/lib/resolver-compat.js
    Critical dependency: the request of a dependency is an expression
    
    Import trace for requested module:
    ./node_modules/degenerator/node_modules/vm2/lib/resolver-compat.js
    ./node_modules/degenerator/node_modules/vm2/lib/main.js
    ./node_modules/degenerator/node_modules/vm2/index.js
    ./node_modules/degenerator/dist/src/index.js
    ./node_modules/pac-resolver/dist/index.js
    ./node_modules/pac-proxy-agent/dist/agent.js
    ./node_modules/pac-proxy-agent/dist/index.js
    ./node_modules/proxy-agent/index.js
    ./node_modules/cloudinary/lib/utils/index.js
    ./node_modules/cloudinary/lib/utils/srcsetUtils.js
    ./node_modules/cloudinary/lib/cloudinary.js
    ./node_modules/cloudinary/cloudinary.js
    ./app/api/image/route.tsx
    
    - info Linting and checking validity of types  
    - info Collecting page data ..Error: ENOENT: no such file or directory, open '/Users/me/my-project/.next/server/chunks/bridge.js'
        at Object.openSync (node:fs:601:3)
        at Object.readFileSync (node:fs:469:35)
        at 78475 (/Users/me/my-project/.next/server/chunks/473.js:54037:120)
        at __webpack_require__ (/Users/me/my-project/.next/server/webpack-runtime.js:25:43)
        at 86577 (/Users/me/my-project/.next/server/chunks/473.js:51797:17)
        at __webpack_require__ (/Users/me/my-project/.next/server/webpack-runtime.js:25:43)
        at 40117 (/Users/me/my-project/.next/server/chunks/473.js:50554:18)
        at __webpack_require__ (/Users/me/my-project/.next/server/webpack-runtime.js:25:43)
        at 88436 (/Users/me/my-project/.next/server/chunks/473.js:50382:15)
        at __webpack_require__ (/Users/me/my-project/.next/server/webpack-runtime.js:25:43) {
      errno: -2,
      syscall: 'open',
      code: 'ENOENT',
      path: '/Users/me/my-project/.next/server/chunks/bridge.js'
    }
    
    > Build error occurred
    Error: Failed to collect page data for /api/image
        at /Users/me/my-project/node_modules/next/dist/build/utils.js:1152:15
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
      type: 'Error'
    }
    
    

    Just in case it helps, here's the compiling error I get after installing "vm2@latest" ("vm2": "^3.9.19"):

    ./node_modules/vm2/lib/compiler.js
    Module not found: Can't resolve 'coffee-script' in '/Users/me/my-project/node_modules/vm2/lib'
    
    Import trace for requested module:
    ./node_modules/vm2/lib/compiler.js
    ./node_modules/vm2/lib/script.js
    ./node_modules/vm2/lib/main.js
    ./node_modules/vm2/index.js
    ./node_modules/degenerator/dist/src/index.js
    ./node_modules/pac-resolver/dist/index.js
    ./node_modules/pac-proxy-agent/dist/agent.js
    ./node_modules/pac-proxy-agent/dist/index.js
    ./node_modules/proxy-agent/index.js
    ./node_modules/cloudinary/lib/utils/index.js
    ./node_modules/cloudinary/lib/utils/srcsetUtils.js
    ./node_modules/cloudinary/lib/cloudinary.js
    ./node_modules/cloudinary/cloudinary.js
    ./app/api/image/route.tsx
    
    ./node_modules/vm2/lib/resolver-compat.js
    Critical dependency: the request of a dependency is an expression
    
    Import trace for requested module:
    ./node_modules/vm2/lib/resolver-compat.js
    ./node_modules/vm2/lib/main.js
    ./node_modules/vm2/index.js
    ./node_modules/degenerator/dist/src/index.js
    ./node_modules/pac-resolver/dist/index.js
    ./node_modules/pac-proxy-agent/dist/agent.js
    ./node_modules/pac-proxy-agent/dist/index.js
    ./node_modules/proxy-agent/index.js
    ./node_modules/cloudinary/lib/utils/index.js
    ./node_modules/cloudinary/lib/utils/srcsetUtils.js
    ./node_modules/cloudinary/lib/cloudinary.js
    ./node_modules/cloudinary/cloudinary.js
    ./app/api/image/route.tsx
    
    - info Linting and checking validity of types  
    - info Collecting page data ..Error: ENOENT: no such file or directory, open '/Users/me/my-project/.next/server/chunks/bridge.js'
        at Object.openSync (node:fs:601:3)
        at Object.readFileSync (node:fs:469:35)
        at 90260 (/Users/me/my-project/.next/server/chunks/473.js:85507:120)
        at __webpack_require__ (/Users/me/my-project/.next/server/webpack-runtime.js:25:43)
        at 63232 (/Users/me/my-project/.next/server/chunks/473.js:83267:17)
        at __webpack_require__ (/Users/me/my-project/.next/server/webpack-runtime.js:25:43)
        at 34088 (/Users/me/my-project/.next/server/chunks/473.js:82024:18)
        at __webpack_require__ (/Users/me/my-project/.next/server/webpack-runtime.js:25:43)
        at 88436 (/Users/me/my-project/.next/server/chunks/473.js:50382:15)
        at __webpack_require__ (/Users/me/my-project/.next/server/webpack-runtime.js:25:43) {
      errno: -2,
      syscall: 'open',
      code: 'ENOENT',
      path: '/Users/me/my-project/.next/server/chunks/bridge.js'
    }
    
    > Build error occurred
    Error: Failed to collect page data for /api/image
        at /Users/me/my-project/node_modules/next/dist/build/utils.js:1152:15
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
      type: 'Error'
    }
    
  • Cloudinary Team
    Cloudinary Team Administrator, Cloudinary Staff Posts: 123 admin
    Options

    Hi there,

    It seems like you are having trouble compiling your code. The error message you provided suggests that the "coffee-script" module is missing. This could be because the module is not installed or it is not installed correctly. You can try installing the module by running the following command in your terminal:

    npm install coffee-script
    

    If that doesn't work, you can try deleting your node_modules folder and running npm install again.

    I hope this helps! Let me know if you have any other questions.
    Regards,
    Wissam

    Developer Support Engineer
    Cloudinary


    Join the Cloudinary Community


  • lalapolalaanewb
    lalapolalaanewb Member Posts: 1
    edited June 2023
    Options

    I'm facing the same issue even after doing all steps up to installing coffee-script manually. Any updates regarding this issue?

    Here's my current setup:

    node: 18.16.0

    cloudinary: 1.37.2

    next: 13.4.3

  • Tamara
    Tamara Member, Cloudinary Staff Posts: 97
    Options

    Hi,

    Please follow the updates and report about issues on the main issue thread here: https://github.com/cloudinary/cloudinary_npm/issues/600

    Thanks,

    Tamara

  • gmzi
    gmzi Member Posts: 3
    edited June 2023
    Options

    Thanks Tamara, heading over to main issue thread

  • valentino_guerra
    valentino_guerra Member Posts: 1
    Options

    I'm facing the same issue too, using Next.js 13. I will try to implement it through basic HTTP requests instead of the SDK. At least until the issue is solved. 😕