Can not install lodash

Describe the problem/error/question

I have installed using the guide on Docker Compose | n8n Docs

Now I want to use custom code with lodash.

I have added the line to docker-compose.yml under environments:

  • NODE_FUNCTION_ALLOW_EXTERNAL=lodash

But still when I run the code with lodash it gives error:
Cannot find module ‘lodash’ [line 1, for item 0]

I understand that I still need to install the module using npm but I have no clue where to run this command?

What is the error message (if any)?

Cannot find module ‘lodash’ [line 1, for item 0]

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

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

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:

I have provided required info, let me know if anything else needed

Hi @mrmegamind,

Welcome to the community :sparkles:

Have you shut down and restarted your instance since adding the variable?
If so, and the error is still showing, you can install it your Dockerfile like so:

FROM docker.n8n.io/n8nio/n8n
USER root
RUN npm install -g lodash
USER node

Here’s an example of another user who ran into the same issue: Adding packages to a docker install - #2 by jan

1 Like

Thanks for your feedback @mariana-na

But I still do not understand how to merge this with the installation steps from Docker Compose | n8n Docs

Because we are starting with “sudo docker compose up -d”

This might be something very basic but I am new to docker so can not figure out

I think you need two steps.

  1. Effect the environment you added in docker-compose.
    Please enter the directory where docker-compose.yml exists, and then restart by:
sudo docker-compose down
sudo docker-compose up -d
  1. Run npm command, make sure n8n is running, then enter the container.
sudo docker-compose exec -it n8n /bin/sh

#Now run the npm command in the container shell
2 Likes

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