Building custom nodes in a monorepo, possible?

Greetings community!
We are building custom nodes with n8n in an effort to provide pre-fabricated functions for our non-technical team members to build workflows with.

It seems this might not be possible with our monorepo and would love some clarity here.

Context
Our product and its associated backend functions are in a monorepo build with pnpm, meaning we are using ESModules in order to allow our applications in the apps/ workspace to draw from source code in our packages/ workspace, a very typical setup, and has been working well for our NextJS build for a while now.

Build
The n8n custom node starter template was placed as an app inside our apps/ directory, and we were able to successfully build the two example nodes provided out of the box! :grinning: :+1:

After building, we installed the nodes with npm link, and they appeared in the UI.

Issue
The issue arises when we add in an import for a package from our packages/ pnpm workspace.
Similar to our NextJS code, we added the package as a dependency in the n8n custom node starter package.json, and then run pnpm install.

Though the package is installed as expected similar to our NextJS app, the typescript parser will error on trying to import a named export from this newly installed package.
The typescript parser will say the expected, that we cannot import from the local monorepo package with a package type of CommonJs.
Indeed, checking our NextJS build, we have a type of module

Changing the n8n starter to type module will allow us to import the custom package as expected, and the build runs, however instead of producing CommonJs code, ESmodule code is output instead, and n8n will complain that it cannot run this code.

Error [ERR_REQUIRE_ESM]: require() of ES Module ~/ape-analytics/apps/n8nodes/dist/nodes/ExampleNode/ExampleNode.node.js from ~/.nvm/versions/node/v20.11.1/lib/node_modules/n8n/node_modules/n8n-core/dist/ClassLoader.js not supported.

Is it possible for us to build custom nodes pulling from our group’s packages within our monorepo similar to how we build our other apps such as NextJS?

Thank you kindly for your support and time reading out question!

Information on your n8n setup

  • n8n version: 1.38.2
  • Database: SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via: n8n command installed with npm
  • Operating system: MacOS Sonoma 14.4.1
1 Like

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey @paulmikulskis,

Welcome to the community :partying_face:

At the moment we only officially support the method we provide but in theory as long as you are able to build the files correctly which looks to be the issue you are hitting. I don’t have any instructions on how to make it work so it will involve some more trial and error if you wanted to continue down that path but it could be easier and quicker to have a separate repo for your n8n nodes.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.