I have been trying to install external modules like ‘moment’, ‘lodash’ locally on my n8n dashboard. I have installed it in my n8n/node_modules folder. When I try to ‘require’ it in my function node it gives me error as “cannot find module ‘lodash’”. I have followed the steps mentioned at https://docs.n8n.io/#/configuration by setting the environment variables as
export NODE_FUNCTION_ALLOW_EXTERNAL=lodash but still doesn’t work. I am looking for a way to make it happen I’d really appreciate a quick response. Thank you in advance.
Sorry, do not understand where you want to use this modules? If you say in your “n8n dashboard” you mean you are changing the actual UI? Or do you mean you want to use it in a Fuction-Node?
@chinmay_chavan working on a node that format dates so that you do not have to import any packages. Is that the use case you are looking for?
@chinmay_chavan did play around with it two days ago and now today again. Sadly does now work like expected. It works fine in the dev-environment but not when installed regularly. Hope I can figure out the problem soon.
Ok did figure out the issue. I did actually already find it two days ago but never worked in my tests anyway (which confused me a lot). I just found out why. I always changed the code in the Function-Node but my test workflow had the FunctionItem-Node. Totally stupid!!! Hours waisted for nothing. Anway is fixed now and will be released with the next version.
Ok released now [email protected] with the fix.
Just tested like that and it works now fine:
# Go in folder you want to install n8n in and install n8n with the modules you need npm install n8n moment # Allow access to the modules export NODE_FUNCTION_ALLOW_EXTERNAL=moment # Start n8n node node_modules/.bin/n8n
Could you suggest a way I can make this work with the Docker container, please? Or, will this only work with standalone installs?
Haha! We’ve all been there mate! Thank you for taking out the time to work on this and making it work! Kudos!
I’ll try this out and get back here, Thanks once again!
It is theoretically also possible with the docker image but much more messy as you have to mount each module you need separate. For “sugar-date” that would for example additionally be “sugar-core” as “sugar-'date” depends on it. The more complex the module you need the more modules that would be. So for it to work you would have to:
- npm install “sugar-date” (or whatever you want) in a folder (in this example it would be
- Then start the n8n container kind of like this:
docker run -it --rm \ --name n8n \ -p 5678:5678 \ -e NODE_FUNCTION_ALLOW_EXTERNAL=sugar-date \ -v ~/.n8n:/root/.n8n \ -v ~/whereever-you-have-the-module/node_modules/sugar-core:/usr/local/lib/node_modules/sugar-core \ -v ~/whereever-you-have-the-module/node_modules/sugar-date:/usr/local/lib/node_modules/sugar-date \ n8nio/n8n:0.51.0
That worked perfectly! Thanks a lot, @jan.
Will stick to the Docker container for now and then move on to a native install if I end up needing lots of such modules.
Great to hear that it worked! Wish you a great day!
For anyone wondering how to allow multiple, just put them in a comma separated list like so
(as a multiple export of the single value will obviously override the previous one)
Great feature, thanks
For those who want to use date-fns and date-fns-tz (tz stands for timezone), in order to have it fully supported (
full-icu)you need nodejs > 13. I ran into an issue:
The module ‘/var/www/vhosts/rz.gl/mat.rz.gl/node_modules/mmmagic/build/Release/magic.node’
was compiled against a different Node.js version using
I solved it by first updating nodejs and npm to latest version and then running
npm rebuild mmmagic--update-binary