Cannot import node module "cloudinary" - VMError

Describe the problem/error/question

I’m trying to use the Cloudinary SDK through NPM packages import.
But, it’s failing.

What is the error message (if any)?

const cloudinary = require('cloudinary').v2;

Throws:

Cannot find module ‘cloudinary’ [line 1]

VMError

I tried importing it using import instead. (see Code node, cannot use external npm module - #7 by Jon)

import { v2 as cloudinary } from 'cloudinary';

Throws:

‘import’ and ‘export’ may only appear at the top level [line 1]

SyntaxError

Share the output returned by the last node

Information on your n8n setup

  • n8n version: latest
  • Database (default: SQLite): Probably
  • n8n EXECUTIONS_PROCESS setting (default: own, main): No idea what this is
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker, via Cloudron
  • Operating system: Ubuntu 22

env.sh

# https://docs.n8n.io/reference/environment-variables.html
export EXECUTIONS_DATA_SAVE_MANUAL_EXECUTIONS=true
export EXECUTIONS_DATA_SAVE_ON_ERROR=all
export EXECUTIONS_DATA_SAVE_ON_SUCCESS=all
export N8N_LOG_LEVEL=info

export EXECUTIONS_DATA_PRUNE=true
export EXECUTIONS_DATA_MAX_AGE=672

# Allow node modules to be used in code node - https://docs.n8n.io/hosting/configuration/#use-built-in-and-external-modules-in-the-code-node
# Allows usage of all builtin modules
export NODE_FUNCTION_ALLOW_BUILTIN=*

# Allow usage of external npm modules.
export NODE_FUNCTION_ALLOW_EXTERNAL=cloudinary

Hey @Vadorequest, sorry to hear you’re having difficulties here. I just messaged another community member who was figuring out how to import node modules as well so I’ll share some of the same resources as I did there.

You can use the wildcard value for the external npm modules you want to allow instead of specifying the individual name. I’d also recommend checking to make sure you’re installing them globally, and rebuilding your docker container.

Other helpful threads:

Thanks!

I hadn’t installed those npm modules on my instance.
I’m using Cloudron to install n8n and I’m not sure how those are supposed to be installed, I couldn’t find any documentation about the process.

Thanks for hinting about the wildcard option, much simpler and avoids having to restart the instance, too.

After looking it up, I can confirm Cloudron is auto-installing modules specified in the EXTRA_NODE_MODULES.

Source:

Unfortunately, I’m still facing the same error.

Could you try and see if that particular module is compatible with n8n?

export [email protected]

Thank you

The issue is solved.

It was related to Cloudron’s configuration which wasn’t properly documented. See How to install NPM packages that n8n App can use? | Cloudron Forum

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.