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!
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