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

**URL:** <https://community.n8n.io/t/custom-node-in-dockerfile-throwing-cannot-find-module-n8n-workflow/24898>\
**Category:** Questions\
**Tags:** deployment, docker\
**Created:** [April 6, 2023, 1:51am UTC](https://community.n8n.io/t/custom-node-in-dockerfile-throwing-cannot-find-module-n8n-workflow/24898 "2023-04-06T01:51:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pepe](https://avatars.discourse-cdn.com/v4/letter/p/4da419/32.png) [@Pepe](https://community.n8n.io/u/Pepe)\
**Post date:** [April 6, 2023, 1:51am UTC](https://community.n8n.io/t/custom-node-in-dockerfile-throwing-cannot-find-module-n8n-workflow/24898/1 "2023-04-06T01:51:20Z")

</div>

Hey 👋

## 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:

```auto
[+] 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 > n8n-nodes-stellar@0.1.0 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:

```auto
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:

```auto
{
	"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

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [April 11, 2023, 1:16pm UTC](https://community.n8n.io/t/custom-node-in-dockerfile-throwing-cannot-find-module-n8n-workflow/24898/2 "2023-04-11T13:16:48Z")

</div>

Hi @Pepe, from checking [Install private nodes - n8n Documentation](https://docs.n8n.io/integrations/creating-nodes/deploy/install-private-nodes/#install-your-node-in-a-docker-n8n-instance) 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 🙈

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

---

<div class="post-metadata">

**Author:** ![Pepe](https://avatars.discourse-cdn.com/v4/letter/p/4da419/32.png) [@Pepe](https://community.n8n.io/u/Pepe)\
**Post date:** [April 12, 2023, 12:20am UTC](https://community.n8n.io/t/custom-node-in-dockerfile-throwing-cannot-find-module-n8n-workflow/24898/3 "2023-04-12T00:20:32Z")

</div>

Hey @MutedJam,

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

Thanks!  
Cheers.

---

<div class="post-metadata">

**Author:** ![Jon](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jon/32/40174_2.png) [@Jon](https://community.n8n.io/u/Jon)\
**Post date:** [April 13, 2023, 8:15am UTC](https://community.n8n.io/t/custom-node-in-dockerfile-throwing-cannot-find-module-n8n-workflow/24898/4 "2023-04-13T08:15:41Z")

</div>

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.

```auto
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

```auto
**/.git
**/node_modules

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [April 20, 2023, 8:16am UTC](https://community.n8n.io/t/custom-node-in-dockerfile-throwing-cannot-find-module-n8n-workflow/24898/5 "2023-04-20T08:16:03Z")

</div>

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