How to use external libs in function node?

Hi,

I cannot use external libs inside the function node.
here I use,
NODE_FUNCTION_ALLOW_EXTERNAL=axios,moment,node-redshift

Showing error : Cannot find module ‘node-redshift’ [Line 377]

Anyone can help with this.

Thanks.

Hi :slight_smile:

The corresponding packages must also be installed in the n8n installation directory via npm.

However, axios is already a “built-in” function. Simply also enable axios in NODE_FUNCTION_ALLOW_BUILTIN

1 Like

Hi @BillAlex

Ok, Then how do we use node-redshift. Even,

NODE_FUNCTION_ALLOW_EXTERNAL=node-redshift – this not work.

The npm module still has to be installed to be able to be used. How to, for example, create an own docker image to do that, can be found for example here:

My settings:
Windows 10
n8n: v0.158.0
npm: v8.3.1
node: v14.17.3

My workflow:
navigate to C:\Users\{USERNAME}\AppData\Roaming\npm\node_modules\n8n

npm install node-redshift

set NODE_FUNCTION_ALLOW_EXTERNAL=*
set NODE_FUNCTION_ALLOW_EXTERNAL=node-redshift
::Both tested

n8n

::in n8n ui function node
const redshift = require('node-redshift')

Works for me.

1 Like

Ah, you are running n8n via npm. Then what you wrote looks like the 100% correct solution. Thanks a lot for sharing!

@jan

This is correct or not,

docker run -it -d --rm *
** --name n8n-demo1 *

** -p 5678:5678 **
** -e NODE_FUNCTION_ALLOW_EXTERNAL=node-redshift **
** -v ~/.n8n:/root/.n8n **
** -v ~/home/{username}/node_modules/node-redshift:/usr/local/lib/node_modules/n8n/node_modules/node-redshift **
** n8nio/n8n:0.51.0**

this also not working.

Can not imagine so. node-redshift will have additional dependencies which you would all have to mount in for it to work correctly. For that reason the advice to build an own docker image in the other post.

Ok, Thanks Jan. :+1:

Just fyi it is planned to make that easier in the future. We sadly did just not find the time for it yet.

@jan, It’s ok. Sorry for asking again, why some libs are not supported.

Here, node-redshift libs are working but aws-redshift is not working. don’t know why?

It is less about them not being supported, they and their dependencies are just not installed.
So to make them work do they have to get installed.

If n8n got installed via npm then those modules also have to get npm installed, and if n8n runs in Docker then they have to be installed inside of that Docker container.

As soon as the code of those packages is there they can be used as long as NODE_FUNCTION_ALLOW_EXTERNAL gets set accordingly.

Hope that makes sense.

1 Like

Hey @jan,

Ya, it’s true. some of the dependencies are not supported. I can do it with other libs.

Thank you for the time @jan.