Using Jsonata
-
-
OK, on investigation what I found is:
- n8n uses vm2 to run code.
- vm2 in turn uses node's built-in vm module.
- However, vm2 does not use NODE_PATH - https://github.com/patriksimek/vm2/blob/master/lib/sandbox.js#L250 . So, the solution that I had earlier is wrong. It just happened to work for handlebars and some other random modules I tried.
All this means that we can only use the modules in
/app/code/node_modules
.Since jsonata seems generally useful, I have included it in the package itself. Let me know if you need other node modules and I can add them.
-
@robi each module brings it's own set of dependencies. So, we have lots of folder of symlink taking into account somehow that they might conflict with upstream's node dependencies. npm usually sorts this all out keeping directory structure flat and gives each module it's own copy when modules conflict, very hard to just symlink.
-
@robi usually
NODE_PATH
works. It's an additional path where system wide node_modules can be found. But it doesn't work with thevm
module.Symlinking all of node_modules essentially means copying over all the code to a writable location and installing user modules on application startup. We might as well run the app from
/app/data
at this point. Generally, we don't do this in Cloudron unless there is no other way and we cannot live without it. -
@girish I see.
looking at vm2 there are ways to specify modules by relative paths in the script.
https://www.npmjs.com/package/vm2/v/3.6.4?activeTab=readmeCtrl-f on "Loading modules by relative path"
same here:
https://github.com/patriksimek/vm2Here it mentions using NODE_EXECUTABLE
https://pypi.org/project/node-vm2/ -