Closed pablorq closed 1 year ago
Hey @pablorq,
The recommended way to add a package would be to use a custom image, To do this you can follow the example below.
FROM n8nio/n8n:latest
USER root
RUN npm install -g @mozilla/readability
USER node
The other option would be to run the below
docker exec -u root -it n8n /bin/sh
npm install -g @mozilla/readability
I have done a quick test and both of these options work using your example code snippet
The /home/node/.n8n/nodes/
path is only used to load custom nodes not any npm package you want to use in the code node.
Tried with this:
/home/node # whoami
root
/home/node # npm install -g @mozilla/readability
added 1 package in 2s
/home/node # cd /usr/local/lib/node_modules/
/usr/local/lib/node_modules # ls -hal
total 32K
drwxr-sr-x 1 root root 4.0K Oct 9 11:30 .
drwxr-sr-x 1 root root 4.0K Aug 10 19:24 ..
drwxr-sr-x 3 root root 4.0K Oct 9 11:30 @mozilla
drwxr-sr-x 4 root root 4.0K Aug 10 19:24 corepack
drwxr-sr-x 4 root root 4.0K Aug 31 14:08 full-icu
drwxr-sr-x 6 root root 4.0K Sep 25 12:14 n8n
drwxr-sr-x 1 root root 4.0K Aug 31 14:08 npm
/usr/local/lib/node_modules #
It is installed, but still the same error:
Any idea?
Every additional node_module needs to be explicitly added to an allow list.
can you try setting the env variable NODE_FUNCTION_ALLOW_EXTERNAL=@mozilla/readability
.
Ouch!
I've deleted it in some test. In fact I'm using `- NODE_FUNCTION_ALLOW_EXTERNAL=* in the docker compose file.
The npm install -g [package-name]
did the trick.
Now it works. Thank you!
Describe the bug A package/module installed using npm in the
/home/node/.n8n/nodes/
user directory can't be used inside a Code node.To Reproduce Steps to reproduce the behavior:
npm install --prefix=/home/node/.n8n/nodes/ @mozilla/readability
commandERROR: Cannot find module ...
Expected behavior Be able to use any installed Node.js package inside a Code node.
Environment (please complete the following information):
own
,main
andqueue
. Default ismain
]Additional context Docker compose file (portainer version):
Content of ${N8N_LOCAL_FILES}/n8n-config/init-data.sh to initialize n8n database:
Output from container's console:
Create a simple workflow with a Code node with the following:
Complete error shown in n8n:
Also checked on: https://community.n8n.io/t/install-npm-package/3080/2 https://docs.n8n.io/hosting/installation/npm/#windows-troubleshooting https://community.n8n.io/t/installing-additional-module-with-npm/11682/8 https://community.n8n.io/t/can-i-install-npm-packages/18434/2 https://community.n8n.io/t/can-i-install-npm-packages/18434/2 https://blog.elest.io/how-to-install-additional-libraries-for-n8n/ https://docs.n8n.io/integrations/community-nodes/installation/manual-install/