Do you have to create a "n8n-nodes-modules" to have dependencies?

Hello, I’m creating a node, but I need to pull in an NPM dependency. It seems like the only way to accomplish this is to create my own custom “n8n-nodes-modules”, is that correct?
The docs seem to suggest if you go this route you’re surrendering your ability to share this node with others. I’m working on a node to calculate sunrise, sunset times and thought I’d make it available to other n8n contributors when I finished. I couldn’t find a definitive answer anywhere whether dependencies are a custom n8n-node-module only thing.

It depends.

If the module is already used in n8n then it is not necessary. Also if you add the node to n8n-nodes-base and add the dependency there it would not have to be an own module either as it would become part of the core product. Anyway, such a node would probably not be merged as we try to keep the number of external dependencies low.

So in this case, a separate n8n module would probably be best. We have also planned to make it easier in the future to load such external modules. Currently, it is still way to complicated. It will then be possible to load them easily via the UI with just a few clicks. Sadly have no ETA for that yet.

1 Like

Gotcha. Thank you for the detailed response! Creating a custom node module did end up working out for me nicely even if it felt a little overkill. The template you made helped a ton with setup, base nodes made good reference too. I’ll keep those dependencies in mind next time I’m writing a node, Moment.JS will probably come in handy again.

I’ll be on the lookout when that update comes in! I understand these things can take a while. But, your work on this project is appreciated. After IFTTT added pricing and with Zapier, Integromat being so expensive, n8n offers incredible value.

Hi Jan,

I’m trying to use redis module which is already part of core nodes, but I’m getting Cannot find module 'redis' or its corresponding type declarations. error when I try to build it using n8n-node-dev build. If I create a package.json file in next to my node source code, then the build work, but n8n won’t start also complaining about not finding the module (node:98591) UnhandledPromiseRejectionWarning: Error: There was an error: Cannot find module 'redis'

Any idea why this is happening?

Yes, the module does already get used, so the node will run fine once it is built. The problem here is that TypeScript still expects the module to be present when the node does get built (to be more exact its declarations). That is kind of its job, to inform you that there is something wrong (and if the declarations are not there it can not do that and that is why it errors).

What you can do here is to tell TypeScript that it should ignore it. That can be done with: // @ts-ignore

So you add it in the line before the import like this:

// @ts-ignore
import * as redis from 'redis';

Another way is to import it the “old fashioned” way with require that it does not look for declarations like this:

const reqis = require('redis');

Thanks for prompt reply!

However, the above didn’t work. It did help with building the node, but n8n start still fails after that (same as it did with my package.json workaround in original message):

$ n8n start
(node:16778) UnhandledPromiseRejectionWarning: Error: There was an error: Cannot find module 'redis'
Require stack:
- /Users/joe/.n8n/custom/RedisQueue.node.js
- /Users/joe/.nvm/versions/node/v14.2.0/lib/node_modules/n8n/dist/src/LoadNodesAndCredentials.js
- /Users/joe/.nvm/versions/node/v14.2.0/lib/node_modules/n8n/dist/src/index.js
- /Users/joe/.nvm/versions/node/v14.2.0/lib/node_modules/n8n/dist/commands/start.js
- /Users/joe/.nvm/versions/node/v14.2.0/lib/node_modules/n8n/node_modules/@oclif/config/lib/plugin.js
- /Users/joe/.nvm/versions/node/v14.2.0/lib/node_modules/n8n/node_modules/@oclif/config/lib/config.js
- /Users/joe/.nvm/versions/node/v14.2.0/lib/node_modules/n8n/node_modules/@oclif/config/lib/index.js
- /Users/joe/.nvm/versions/node/v14.2.0/lib/node_modules/n8n/node_modules/@oclif/command/lib/command.js
- /Users/joe/.nvm/versions/node/v14.2.0/lib/node_modules/n8n/node_modules/@oclif/command/lib/index.js
- /Users/joe/.nvm/versions/node/v14.2.0/lib/node_modules/n8n/bin/n8n
    at Object.error (/Users/joe/.nvm/versions/node/v14.2.0/lib/node_modules/n8n/node_modules/@oclif/errors/lib/index.js:26:15)
    at Start.error (/Users/joe/.nvm/versions/node/v14.2.0/lib/node_modules/n8n/node_modules/@oclif/command/lib/command.js:60:23)
    at /Users/joe/.nvm/versions/node/v14.2.0/lib/node_modules/n8n/dist/commands/start.js:134:22
(Use `node --trace-warnings ...` to show where the warning was created)
(node:16778) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see (rejection id: 2)
(node:16778) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Additionally, the const redis = require('redis'); doesn’t work even for build. It complains with:

RedisQueue.node.ts(62,23): error TS2503: Cannot find namespace 'redis'.

But that’s not important as TypeScript annotation solution works for build.

Hi Jan,

Have things changed regarding this in the recent past? I would like to consume plausible analytics via web scraping and I need to pull puppeteer as a dependency.

Ah sorry @filipkis, missed your message. In this case it is probably best if you create your own n8n-node-module.

@arsalagrey, no nothing changed. Also in your case I would suggest a custom separate n8n-node-module.