Custom node in Dockerfile throwing Cannot find module 'n8n-workflow'

Hey :wave:

Describe the problem/error/question

I needed a customized node so I created an app (Typescript) that I run locally with my own nodes and I’ve to npm link n8n to serve that on my localhost and see my nodes.

What is the error message (if any)?

I’m trying to dockerize the app with Dockerfile, but when I try to build the image it says that Cannot find module ‘n8n-workflow’

The error:

[+] Building 19.8s (12/14)                                                                                                                                                                                                                                                                        => [internal] load build definition from Dockerfile                                                                                                                                                                                                                                        0.0s  => => transferring dockerfile: 415B                                                                                                                                                                                                                                                        0.0s  => [internal] load .dockerignore                                                                                                                                                                                                                                                           0.0s  => => transferring context: 2B                                                                                                                                                                                                                                                             0.0s  => [internal] load metadata for docker.io/n8nio/n8n:latest                                                                                                                                                                                                                                 0.7s  => [ 1/10] FROM docker.io/n8nio/n8n:latest@sha256:81f60515c7d8b754b001af5a4079dd6b47e4d5179c5ca569670e992bd4f4b782                                                                                                                                                                         0.0s  => [internal] load build context                                                                                                                                                                                                                                                           0.7s  => => transferring context: 941.70kB                                                                                                                                                                                                                                                       0.6s  => CACHED [ 2/10] RUN npm install --global --unsafe-perm n8n typescript                                                                                                                                                                                                                    0.0s  => CACHED [ 3/10] WORKDIR /usr/src/app                                                                                                                                                                                                                                                     0.0s  => CACHED [ 4/10] COPY package*.json ./                                                                                                                                                                                                                                                    0.0s  => [ 5/10] COPY . .                                                                                                                                                                                                                                                                        1.6s  => [ 6/10] RUN npm install                                                                                                                                                                                                                                                                10.2s  => [ 7/10] RUN npm install typescript                                                                                                                                                                                                                                                      3.1s  => ERROR [ 8/10] RUN npm run build && npm link                                                                                                                                                                                                                                             3.3s ------                                                                                                                                                                                                                                                                                            > [ 8/10] RUN npm run build && npm link:                                                                                                                                                                                                                                                        #12 1.011                                                                                                                                                                                                                                                                                        #12 1.011 > [email protected] build                                                                                                                                                                                                                                                        #12 1.011 > tsc && gulp build:icons                                                                                                                                                                                                                                                              #12 1.011                                                                                                                                                                                                                                                                                        #12 3.254 credentials/StellarApi.credentials.ts(1,50): error TS2307: Cannot find module 'n8n-workflow' or its corresponding type declarations.                                                                                                                                                   #12 3.255 nodes/Stellar/Stellar.node.ts(6,8): error TS2307: Cannot find module 'n8n-workflow' or its corresponding type declarations.                                                                                                                                                            #12 3.255 nodes/Stellar/actions/newAccount/createAccount/execute.ts(2,40): error TS2307: Cannot find module 'n8n-workflow' or its corresponding type declarations.                                                                                                                               #12 3.256 nodes/Stellar/actions/newAccount/fundAccount/execute.ts(2,61): error TS2307: Cannot find module 'n8n-workflow' or its corresponding type declarations.                                                                                                                                 #12 3.257 nodes/Stellar/actions/newAccount/index.ts(1,33): error TS2307: Cannot find module 'n8n-workflow' or its corresponding type declarations.                                                                                                                                               #12 3.257 nodes/Stellar/actions/payments/getPayment/description.ts(1,33): error TS2307: Cannot find module 'n8n-workflow' or its corresponding type declarations.                                                                                                                                #12 3.257 nodes/Stellar/actions/payments/getPayment/execute.ts(1,35): error TS2307: Cannot find module 'n8n-workflow' or its corresponding type declarations.                                                                                                                                    #12 3.257 nodes/Stellar/actions/payments/index.ts(1,33): error TS2307: Cannot find module 'n8n-workflow' or its corresponding type declarations.                                                                                                                                                 #12 3.258 nodes/Stellar/actions/router.ts(1,68): error TS2307: Cannot find module 'n8n-workflow' or its corresponding type declarations.                                                                                                                                                         #12 3.258 nodes/Stellar/actions/router.ts(22,26): error TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type 'typeof import("/usr/src/app/nodes/Stellar/actions/payments/index")'.                                                          #12 3.258 nodes/Stellar/actions/swapAssets/index.ts(1,33): error TS2307: Cannot find module 'n8n-workflow' or its corresponding type declarations.                                                                                                                                               #12 3.258 nodes/Stellar/actions/swapAssets/swap/description.ts(1,33): error TS2307: Cannot find module 'n8n-workflow' or its corresponding type declarations.                                                                                                                                    #12 3.258 nodes/Stellar/actions/swapAssets/swap/execute.ts(1,35): error TS2307: Cannot find module 'n8n-workflow' or its corresponding type declarations.                                                                                                                                        #12 3.258 nodes/Stellar/transport/index.ts(1,40): error TS2307: Cannot find module 'n8n-workflow' or its corresponding type declarations.                                                                                                                                                        ------                                                                                                                                                                                                                                                                                           executor failed running [/bin/sh -c npm run build && npm link]: exit code: 2   

My Dockerfile:

ARG N8N_VERSION=latest
FROM n8nio/n8n:$N8N_VERSION as build

RUN npm install --global --unsafe-perm n8n typescript

WORKDIR /usr/src/app

COPY package*.json ./

COPY . .

RUN npm install

RUN npm run build && npm link

WORKDIR /usr/local/lib/node_modules/n8n

RUN npm link n8n-nodes-stellar

CMD ["n8n", "start"]

EXPOSE 5678

And my package.json:

{
	"name": "n8n-nodes-stellar",
	"version": "0.1.0",
	"description": "",
	"keywords": [
		"n8n-community-node-package"
	],
	"license": "MIT",
	"homepage": "",
	"author": {
		"name": "",
		"email": ""
	},
	"repository": {
		"type": "git",
		"url": "https://github.com/<...>/n8n-nodes-<...>.git"
	},
	"main": "index.js",
	"scripts": {
		"build": "tsc && gulp build:icons",
		"dev": "tsc --watch",
		"format": "prettier nodes credentials --write",
		"lint": "eslint nodes credentials package.json",
		"lintfix": "eslint nodes credentials package.json --fix",
		"prepublishOnly": "npm run build && npm run lint -c .eslintrc.prepublish.js nodes credentials package.json",
		"test": "vitest nodes"
	},
	"files": [
		"dist"
	],
	"n8n": {
		"n8nNodesApiVersion": 1,
		"credentials": [
			"dist/credentials/StellarApi.credentials.js"
		],
		"nodes": [
			"dist/nodes/Stellar/Stellar.node.js"
		]
	},
	"devDependencies": {
		"@types/express": "^4.17.6",
		"@types/request-promise-native": "~1.0.15",
		"@typescript-eslint/parser": "~5.45",
		"eslint-plugin-n8n-nodes-base": "^1.11.0",
		"gulp": "^4.0.2",
		"n8n-core": "*",
		"n8n-workflow": "*",
		"prettier": "^2.7.1",
		"typescript": "~4.8.4",
		"vitest": "^0.29.2"
	},
	"dependencies": {
		"stellar-sdk": "^10.4.1"
	}
}

Information on your n8n setup

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

Hi @Pepe, from checking Install private nodes - n8n Documentation it seems the suggested way would be to make your custom nodes available in the /home/node/.n8n/custom directory. Though tbh, I am never sure about the best practice when it comes to this, the logic around this has changed too much for me to keep track of it :see_no_evil:

Perhaps our chief node builder @marcus can chip in on this one?

Hey @MutedJam,

I have resolved this by moving the ‘n8n-workflow’ dependency from devDependencies to dependencies.

Thanks!
Cheers.

1 Like

Hey @Pepe,

Moving it to be a dependency is going to result in more space being taken up and could potentially result in other issues.

If I am working on a node and I want to create an image that uses it I tend to have a docker file like the one below at the root of my project.

ARG N8N_VERSION
FROM n8nio/n8n:$N8N_VERSION

RUN npm config set -g production false

RUN mkdir /working-dir
COPY . /working-dir
RUN cd /working-dir && npm install && npm run build && npm pack && \
	cd /usr/local/lib/node_modules/n8n && npm install /working-dir/*.tgz

RUN rm -rf /working-dir

RUN npm config set -g production true

Also a .dockerignore of

**/.git
**/node_modules
2 Likes

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