Compatibility problems with Node 20 (using Remix.run)?

caprica
caprica Member Posts: 11
edited September 13 in Developer APIs

I am using Cloudinary with Node 20 and Remix.run, invoking Cloudinary via the NodeJS API.

With the latest version of Remix, it uses Vite as the build/bundler tool instead of Webpack.

With only this code in a server component (e.g. upload.server.ts):

import { v2 as cloudinary } from 'cloudinary'

cloudinary.config({
    cloud_name: 'blah',
    api_key: 'blah',
    api_secret: 'blah,
})

This error message is generated by the Vite bundler when starting the Remix server:

The plugin "vite:dep-pre-bundle" was triggered by this import

    node_modules/cloudinary/lib/api_client/execute_request.js:3:80:
      3 │ const https = /^http:/.test(config().upload_prefix) ? require('http') : require('https');
        ╵                                                                                 ~~~~~~~

✘ [ERROR] Failed to resolve entry for package "https". The package may have incorrect main/module/exports specified in its package.json. [plugin vite:dep-pre-bundle]

Is there a solution for this?

Node version: v20.16.0
Cloudinary version in package.json: v2.3.1
Remix version: 2.12.0

Note that it can be misleading/confusing when troubleshooting this, with old dependencies hanging around giving the illusion of things working when they do not - so each time you run you must delete node_modules/.vite to clear the Vite dependency cache.

Tagged:

Answers

  • caprica
    caprica Member Posts: 11

    This change to vite.config.ts resolves the error, I'm not sure it is 100% solving the issue, but enough for now:

    export default defineConfig({
        optimizeDeps: {
            exclude: ["cloudinary"]
        },
        plugins: [...]
    })
    
    

    Reference: https://remix.run/docs/en/main/guides/dependency-optimization#failed-to-resolve-entry-for-package

  • DannyFromCloudinary
    DannyFromCloudinary Member, Cloudinary Staff Posts: 139

    Hey @caprica.

    Thanks for getting in touch. I'm unfamiliar with webpack/Vite/Remix myself, but if you were able to provide us with a simple github repo that shows the issue you're having, I would be happy to escalate this to the dev team for further investigation.

    Kind regards,
    -Danny