I’ve been encountering persistent issues specifically with crypto packages (like ethers.js, web3.js, and bitcoinjs-lib) in my n8n setup within a Docker container. Non-crypto packages like lodash and axios work perfectly fine, indicating that the environment is set up correctly for external modules in some cases, but not all. I would appreciate any insights or suggestions to resolve this.
What i’ve done so far Installed Multiple Packages*: Installed five npm packages (ethers, web3, axios, lodash, bitcoinjs-lib) in various locations (each time going further with troubleshooting):
Locally in the ~/.n8n/nodes directory.
In the ~/.n8n/nodes/node_modules directory.
In the ~/.n8n/custom directory.
Globally in the Docker container using npm install -g.
Set Environment Variables: Configured NODE_FUNCTION_ALLOW_EXTERNAL in the docker-compose.yml file to include all these packages, and even tried allowing all external modules with *. Additionally, tried setting N8N_CUSTOM_EXTENSIONS to ~/.n8n/nodes as well as ~/.n8n/nodes/node_modules and ~/.n8n/custom’.
Testing and Verification:
Verified that non-crypto packages (lodash, axios) work as expected in n8n’s Function nodes when included in NODE_FUNCTION_ALLOW_EXTERNAL. Removing them from this variable results in the expected “module not found” errors, confirming that the setup is generally working.
Ran a simple Node.js script directly in the Docker container’s environment to confirm that ethers.js and other packages are operational outside of n8n. This test was successful, indicating the issues are specific to n8n’s integration or configuration.
Permissions and Persistence:
Addressed any permissions issues when attempting global installations.
Ensured that the ~/.n8n directory is mapped to a persistent Docker volume.
The Issue:
Despite the general setup working for non-crypto packages, all crypto-related packages continually result in the following error within n8n: ERROR: Cannot find module 'ethers' [line 1]. This occurs even when the packages are confirmed to be installed and the environment variables are set to allow them.
Seeking Help:
Has anyone in the community faced and resolved similar issues with crypto packages in n8n, particularly within a Docker environment? Any advice on additional steps to troubleshoot or configure the environment would be highly valuable. Here’s what I am particularly curious about:
Are there known issues or additional considerations with crypto packages like ethers.js in n8n?
Might there be additional security or permission layers in Docker affecting access to these packages?
I appreciate any insights or suggestions the community can offer. Thank you for your help!
To use external packages you would need install them globally in the docker container then set the allow_external env option.
Can you share how you attempted to install them globally? I have quickly given it a test using a Dockerfile and it appears to be working as expected for other packages like tesseract.
Besides this, i have also installed ethers normally in multiple locations as i mentioned before.
Also, in the previous post you can see that the external env is setup correctly, i guess?
That is “sadly” not how Docker works. You have to use the currently running container and then create a new image from it. You can find some information about how that can e done here:
Anyway, that is still dirty. The best is to create a custom Docker image via a Dockerfile and use the n8n image as a base. Here is one of many examples in the forum where somebody does something like that:
I had this same issue sometime ago, could fix it on windows but not on linux. I don’t use a docker version but the a simple NPM installed version of n8n, as recreating a docker image every single time is quite teadious.
Any solution for the npm installed version instead of docker?
Yup, i also tried it with PM2 before, but then I read somewhere that n8n officially supports/recommends the Docker install. Am I right @jan?
I prefer the npm/pm2 install as well to be honest.
I have been working with @AAQ on the issue and we got it working in docker with custom npm packages. The only issue is, data is not being persisant, meaning if we redeploy we get back to the setup of n8n again.
I do see the file being copied to /var/lib/docker/volumes/n8n-docker_n8n_data/_data. Yet nothing else then my test file. I did create a workflow etc to test with after going through the setup again.
I also checked the docker logs, which don’t give any error what so ever.
I do see the sqllite db inside of the container at: /root/.n8n
I will test it in the meanwhile, but the progress and example will be nice for the forum.
EDIT:
Chaning it to:
volumes:
- n8n_data:/root/.n8n
This did the trick!, its now persistant as the sqllite db is being copied!
One more piece now remains @Jon. We got a lot of workflows, which we currently save manually and upload to our git, as we don’t have the enterprise n8n version. If there away to import these via a command or api?
You shouldn’t be using /root/.n8n which would suggest your docker image is likely not finishing with USER node to set the correct user as included in the example I posted above.
You can use the n8n cli or the API to import workflows, You could also automate exporting the workflows and saving them to git with an n8n workflow.
Hi @Jon I tested it with USER node, but then the docker image is not started. As everything is done on the VPS with the Root account, this was the only way to get it working.
For the workflows exports/imports I used the following, which worked for me:
Everything being done with root shouldn’t cause any issues so I suspect there is possibly more to it and maybe you were running into the old permission issues we would see from when we changed the user.