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
Ludwig
June 14, 2024, 5:37pm
2
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.
Hi @pooria , to use external modules in n8n you’d need to set the NODE_FUNCTION_ALLOW_EXTERNAL environment variable .
I’ve given this a quick go on my side and could run the following workflow as expected:
Result:
[image]
This was the exact Dockerfile I have used:
FROM n8nio/n8n:1.24.1
USER root
RUN npm install -g @tryfabric/martian
USER node
This was my docker-compose.yml:
services:
n8n:
build: .
environment:
- NODE_FUNCTION_ALLOW_EXTERNAL=*
vol…
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:
Hey @atomtr ,
Try using the below and see if that helps.
FROM n8nio/n8n:latest
USER root
RUN npm install -g json2md
USER node
I want to install and extra module, and if I understand correctly from the docs, I need to:
install the extra module
ad an environment variable NODE_FUNCTION_ALLOW_EXTERNAL=modulename
What is not (yet) clear to me, is:
whether I’ve got to install the extra module globally or inside n8n/node_modules folder?
how/where to ad an environment variable. I tried export NODE_FUNCTION_ALLOW_EXTERNAL=modulename but nothing happens
I’m obviously overlooking something very simple, but I don’t know what…
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
system
Closed
July 12, 2024, 8:07am
7
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.