Install an external library with docker compose

I’m trying to install an external module to be used in a ‘code’ node type

It’s the first time I do this so I’m trying with hello-world-npm.

At the end I should be able to have a working ‘code’ node with this:

const helloWorld = require('hello-world-npm');
return [{
  json: {
    foo: helloWorld.helloWorld()
  }
}];

I tried many different things and I kee having this final error:

What did I do?

npm install hello-world-npm

… obviously.

Then, I added ‘NODE_FUNCTION_ALLOW_EXTERNAL=*’ a bit of everywhere since I’m not sure where environment variables should be set:

  • in the Dockerfile: ‘ENV NODE_FUNCTION_ALLOW_EXTERNAL=*’
  • in the docker-compose.yml: in the n8n > environment list
  • in the .env

Then I tried many times to stop and restart containers, build a new image with a new container and so on. It doesn’t work.

Thanks for the help! :pray:

Information on your n8n setup

  • n8n version: 1.64.3
  • Database: default
  • n8n EXECUTIONS_PROCESS setting: default
  • Running n8n via: docker compose
  • Operating system: Ubuntu 22.04

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Can you please show your docker-compose file?
npm install hello-world-npm should be inside a custom Dockerfile which extends the standard n8n image.

The result should be like this

A part of Docker-compose.yml:

  n8n:
    #image: n8nio/n8n
    build:
      context: .
      dockerfile: Dockerfile-n8n
    user: "1000:1000"
    restart: always
    depends_on:
      - db-n8n
    ports:
      - "127.0.0.1:5678:5678"
    labels:
      <SOME TRAEFIK STUFF IF USING TRAEFIK AS REVERSE-PROXY>
    environment:
      <SOME ENV VARIABLES HERE>

      - NODE_FUNCTION_ALLOW_BUILTIN
      - NODE_FUNCTION_ALLOW_EXTERNAL
    volumes:
      - ${DATA_FOLDER}/.n8n:/home/node/.n8n

And then Dockerfile-n8n. Note that I install both system libs + npm packages. System libs are available immediately via Execute Command Node:

ARG tag=latest
FROM n8nio/n8n:$tag
USER root

RUN apk --update add sshpass openssh imagemagick libwebp libwebp-tools ghostscript poppler-utils curl curl-dev libcurl linux-headers g++ gfortran libxml2 libxml2-dev ffmpeg openjdk8-jre libreoffice
RUN apk add --no-cache msttcorefonts-installer fontconfig
RUN update-ms-fonts

RUN npm install -g pdf-image pdf2pic minify [email protected] nunjucks xlsx-template

USER node

Finally, don’t forget about .env file:

NODE_FUNCTION_ALLOW_BUILTIN=*
NODE_FUNCTION_ALLOW_EXTERNAL=luxon,pdf-image,pdf2pic,minify,easy-template-x,pca-js,nunjucks,xlsx-template
2 Likes

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