Unable to add NPM package - Cannot find module

Describe the problem/error/question

I am unable to add custom NPM packages anymore. I had this working just the other day, but when rebuilding my custom image, it’s now unable to find the package

I have followed the steps listed here, and they did initially work, but now I am at a loss as to why it’s broken.

Dockerfile:

FROM n8nio/n8n:latest
USER root
RUN npm install -g word-extractor
USER node

docker-compose.yml

version: "3.7"

services:
  caddy:
    image: caddy:latest
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - caddy_data:/data
      - ${DATA_FOLDER}/caddy_config:/config
      - ${DATA_FOLDER}/caddy_config/Caddyfile:/etc/caddy/Caddyfile

  n8n:
    build: .
    restart: always
    ports:
      - 5678:5678
    environment:
      - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
      - N8N_DIAGNOSTICS_ENABLED=false
      - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
      - N8N_RESTRICT_FILE_ACCESS_TO=/data/shared
      - NODE_FUNCTION_ALLOW_BUILTIN=*
      - NODE_FUNCTION_ALLOW_EXTERNAL=*
      - NODES_EXCLUDE=[]
    volumes:
      - n8n_data:/home/node/.n8n
      - ${DATA_FOLDER}/local_files:/files
      - ./shared:/data/shared

volumes:
  caddy_data:
    external: true
  n8n_data:
    external: true

This is the output from docker compose build:

WARN[0000] /home/ubuntu/n8n-docker-caddy/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion
#1 [internal] load local bake definitions
#1 reading from stdin 517B done
#1 DONE 0.0s

#2 [internal] load build definition from Dockerfile
#2 transferring dockerfile: 113B 0.0s done
#2 DONE 0.0s

#3 [internal] load metadata for docker.io/n8nio/n8n:latest
#3 DONE 0.8s

#4 [internal] load .dockerignore
#4 transferring context: 2B done
#4 DONE 0.0s

#5 [1/2] FROM docker.io/n8nio/n8n:latest@sha256:1ecc41c012acc5a425e43ff4b87193d8c08d00832876df367656eb7e5ee7fc5b
#5 CACHED

#6 [2/2] RUN npm install -g word-extractor
#6 2.965
#6 2.965 added 7 packages in 2s
#6 DONE 3.1s

#7 exporting to image
#7 exporting layers 0.1s done
#7 writing image sha256:c39169c1c1f7c850c699805d7e23cfc86e2ea96a176e681080a76364ce3bcf04 done
#7 naming to docker.io/library/n8n-docker-caddy-n8n done
#7 DONE 0.1s

#8 resolving provenance for metadata file
#8 DONE 0.0s
[+] Building 1/1
 ✔ n8n-docker-caddy-n8n  Built

Hopefully someone can point me in the right direction! I am sure if will be something I have maybe overlooked, but I cannot for the life of me figure out what it is.

What is the error message (if any)?

Cannot find module ‘word-extractor’ Require stack: - /usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+task-runner@file+packages+@n8n+task-runner_@[email protected]_@opentelemetry_eb51b38615a039445701c88b088f88d0/node_modules/@n8n/task-runner/dist/js-task-runner/require-resolver.js - /usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+task-runner@file+packages+@n8n+task-runner_@[email protected]_@opentelemetry_eb51b38615a039445701c88b088f88d0/node_modules/@n8n/task-runner/dist/js-task-runner/js-task-runner.js - /usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+task-runner@file+packages+@n8n+task-runner_@[email protected]_@opentelemetry_eb51b38615a039445701c88b088f88d0/node_modules/@n8n/task-runner/dist/start.js

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

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

you tell it to install it, but not where to find the insallation -

ENV NODE_PATH=/usr/local/lib/node_modules (Change this to where it actually is)