Custom node in docker container throwing "cannot find module" error

Hi :slight_smile: ,

I needed a customized Twitter node, so I copied the original and adapted it for my purposes. I set up the development environment by creating a Docker container, cloning the n8n repository and adding my custom node to the package.json. Everything worked as expected, the node was visible and working correctly.

n8n is running in a separate container along with some other containers, all orchestrated by docker-compose. I used “n8nio/n8n”.

As far as I know, I had to map the path, where my compiled container is, to the path “/root/.n8n/custom/”. This seems to work and the custom node is being picked up. The problem I got is that n8n crashes because it does not find the required dependencies:

"Error: There was an error: Cannot find module ‘n8n-core’".

This error happens in the file “GenericFunctions.js”. I checked and “n8n-core” is installed globally inside the container (just like it should be since I did not alter the Docker container in any way, I just mapped the required volumes).

The compiled javascript looks ok to me:

const n8n_core_1 = require("n8n-core");
const n8n_workflow_1 = require("n8n-workflow");
async function twitterApiRequest(method, resource, body = {}, qs = {}, uri, option = {}) {

Is there anything I missed? Do I have to install the required dependencies locally in my Node?

Any clue would be greatly appreciated :slight_smile:

I have the same issue with cheerio. I’d like for nodes in .n8n/custom to have access to dependencies of n8n.

I was able to make it work by installing all dependencies locally.
Sadly it does not find the globally installed packages, so I just installed all dependencies, including “n8n-core” and “n8n-workflow” locally for each custom node.
Keep in mind that when copying the nodes to the custom directory, you also have to include the local “npm_modules” folder with all required dependencies.

@itd24 I can confirm this is the only way I could get my node to work which is a little bit dissapointing.