I used to work with the solution everybody uses who wants to install additional node_modules for use in the Code node: I installed them as glocal node modules in the docker container. I personally use a custom Dockerfile with lines like:
USER root
RUN npm install -g vcards-js
....
I also set export NODE_FUNCTION_ALLOW_EXTERNAL=* as explained in Enable modules in Code node | n8n Docs but since n8n 2.x it doesn’t work anymore. I only get something like:
To fix this, you need to install the dependency inside the task runner environment rather than globally, either by declaring it in N8N_RUNNERS_JS_PACKAGES so the runner installs it automatically, or by bundling the dependency into a custom task runner or n8n image.
Thanks a lot but I couldn’t find any documentation about the env var you mentioned. And just for understanding: Am I supposed to put this into the environment key of my n8n service in my docker-compose file if I run runners internally?
I believe currently the only ‘stable’ way is making a custom docker image, extending the official task runner image. Inside the Dockerfile you would do npm install with the packages you need.
I’ve done this in my repo to build custom main n8n image (not task runner image), and it works.
The only ‘confusing’ part is that the docker image does not have apk, so you need to first add apk to add npm if I remember correctly.
Any other way of installing npm packages does not seem to work, like running npm install in ExecuteCommand node (no permissions, etc)
@Gkp1 Thanks a lot for your response. I also used to create my own n8n docker image. I always installed the additional node modules globally, but this doesn’t seem to work properly anymore. So I also tried to install my additional modules into /usr/local/lib/node_modules/n8n/ but I still get the error mentioned in my initial post. Could you give me some more details about how you manage to install external node modules and make them available for the Code node in n8n?
In n8n 2.x, you generally don’t “manage” external Node.js modules for the Code node the same way as before.
The Code node runs in an isolated environment, so modules installed globally (npm install -g) or manually copied into node_modules are not reliably available anymore.
The supported approaches are:
Use n8n Community Packages
If the module is packaged as a community node, install it via n8n’s community packages mechanism. This is the only officially supported way to make external functionality available inside n8n.
Keep the Code node self-contained
The Code node is intended for logic using built-in Node.js APIs and simple JS, not as a general-purpose runtime with arbitrary npm dependencies.
Move dependency-heavy logic outside n8n
For libraries that must be installed via npm, run them in:
A separate service
An external script
Or another container
…and call it from n8n (HTTP, Execute Command, etc.).
So in short: there is no supported way to “inject” arbitrary npm modules into the Code node anymore. If a dependency is required, it should either be a community package or live outside n8n.