Can I really import external packages in N8N?

Describe the problem/error/question

I am trying to use langchain inside a N8N Code Node. I read everything about that and nothing. this is my Dockerfile

FROM docker.n8n.io/n8nio/n8n
USER root
RUN cd /usr/local/lib/node_modules/n8n/node_modules && npm install langchain

This is the environment of my docker-compose.yml
environment:
- N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
- N8N_BASIC_AUTH_ACTIVE=TRUE
- N8N_BASIC_AUTH_USER
- N8N_BASIC_AUTH_PASSWORD
- N8N_PORT=5678
- N8N_PROTOCOL=https
- NODE_ENV=production
- WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
- GENERIC_TIMEZONE=${GENERIC_TIMEZONE}

  - NODE_FUNCTION_ALLOW_BUILTIN=*
  - NODE_FUNCTION_ALLOW_EXTERNAL= opeanai,langchain,dotenv**

What is the error message (if any)?

When I build container using this command
docker compose up -d --build

I got this error

=> ERROR [n8n 2/2] RUN cd /usr/local/lib/node_modules/n8n/node_modules 55.2s

[n8n 2/2] RUN cd /usr/local/lib/node_modules/n8n/node_modules && npm install langchain:
55.10 npm ERR! code ERESOLVE
55.10 npm ERR! ERESOLVE could not resolve
55.10 npm ERR!
55.10 npm ERR! While resolving: [email protected]
55.10 npm ERR! Found: [email protected]
55.10 npm ERR! node_modules/mysql2
55.10 npm ERR! mysql2@“~2.3.0” from [email protected]
55.10 npm ERR! node_modules/n8n-nodes-base
55.10 npm ERR! n8n-nodes-base@“1.9.3” from the root project
55.10 npm ERR! peerOptional mysql2@“^2.2.5 || ^3.0.1” from [email protected]
55.10 npm ERR! node_modules/typeorm
55.10 npm ERR! typeorm@“^0.3.17” from the root project
55.10 npm ERR! peerOptional typeorm@“^0.3.12” from [email protected]
55.11 npm ERR! node_modules/langchain
55.11 npm ERR! langchain@“" from the root project
55.11 npm ERR! 1 more (the root project)
55.11 npm ERR!
55.11 npm ERR! Could not resolve dependency:
55.11 npm ERR! peerOptional mysql2@“^3.3.3” from [email protected]
55.11 npm ERR! node_modules/langchain
55.11 npm ERR! langchain@"
” from the root project
55.11 npm ERR!
55.11 npm ERR! Conflicting peer dependency: [email protected]
55.11 npm ERR! node_modules/mysql2
55.11 npm ERR! peerOptional mysql2@“^3.3.3” from [email protected]
55.11 npm ERR! node_modules/langchain
55.11 npm ERR! langchain@“*” from the root project
55.11 npm ERR!
55.11 npm ERR! Fix the upstream dependency conflict, or retry
55.11 npm ERR! this command with --force or --legacy-peer-deps
55.11 npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
55.11 npm ERR!
55.11 npm ERR!
55.11 npm ERR! For a full report see:
55.11 npm ERR! /root/.npm/_logs/2023-10-15T21_06_28_755Z-eresolve-report.txt
55.11
55.11 npm ERR! A complete log of this run can be found in:
55.11 npm ERR! /root/.npm/_logs/2023-10-15T21_06_28_755Z-debug-0.log


failed to solve: process “/bin/sh -c cd /usr/local/lib/node_modules/n8n/node_modules && npm install langchain” did not complete successfully: exit code: 1

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:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hi @Adan_Palma :wave: Welcome to the community :cake: and sorry you’re having trouble with this!

This is essentially an installation problem with a package, and not n8n - the error you’re getting suggests that the langchain package wants a version of a mysql2 package that conflicts with a package used by n8n :see_no_evil:

This isn’t something we can offer too much support for, but we do have a version of n8n that’s in beta that includes langchain support :smiley:

If you want to upgrade your existing instance you can simply change the Docker image to use the tag ai-beta in your docker-compose file, so it would be:

  n8n:
    image: n8nio/n8n:ai-beta

If you just want to play around a little bit and not update your main instance, you can spin up the LangChain version for testing on a different port (like 5679) via this command:

docker run -it --rm --name n8n -p 5679:5678 -v ~/.n8n:/home/node/.n8n docker.n
2 Likes

I really appreciate your reply, specially because I did not understand reportes error. I will try running with your suggestion. I was really interested in running langchain inside a js code just for i would have more control.

I have a question. When Do you think your beta version with new AI module will be a stable version? In 3 months? Or More?

Thanks

Hi @adanpalma :wave: Welcome to the community :tada:

There isn’t an exact date, so all I can say is as soon as possible :bowing_man:

1 Like