Describe the problem/error/question
When using a Code node, checking the current __dirname shows that it’s /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes.
However, when checking console.log('resolve-path: ', path.resolve()), it shows resolve-path: /home/node.
Although the file /home/node/modules/test/TestNode.node.js exists, I get an error saying it cannot be found when trying to require it.
The console.log('relativePath: ',fs.existsSync(path.resolve(relativePath,‘modules/test/TestNode.node.js’))) shows relativePath: true, meaning the file exists at the constructed path.
I’m using a local Docker setup.
Is there any way to import user code using require?
What is the error message (if any)?
Cannot find module ‘/home/node/modules/test/TestNode.node.js’ [line 16]
Please share your workflow
(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)
Share the output returned by the last node
Information on your n8n setup
-
n8n version: : 1.77.3
-
Database (default: SQLite):: default
-
n8n EXECUTIONS_PROCESS setting (default: own, main):
-
Running n8n via (Docker, npm, n8n cloud, desktop app): : docker
-
Dockerfile
FROM node:20-alpine AS builder
# pnpm 설치
RUN npm install -g pnpm
WORKDIR /app
COPY ./package*.json ./pnpm-lock.yaml* ./
RUN pnpm install --frozen-lockfile --prod
FROM n8nio/n8n:latest
ENV NODE_FUNCTION_ALLOW_EXTERNAL=*
ENV NODE_FUNCTION_ALLOW_BUILTIN=*
USER node
COPY --from=builder --chown=node:node /app/node_modules /usr/local/lib/node_modules
COPY --chown=node:node ./modules /home/node/modules
WORKDIR /home/node
ENTRYPOINT ["n8n"]
- docker-compose.yml
services:
n8n:
build:
context: .
dockerfile: Dockerfile
restart: always
ports:
- "5678:5678"
environment:
- N8N_HOST=localhost
- N8N_PORT=5678
- N8N_PROTOCOL=http
- WEBHOOK_URL=http://localhost:5678/
- GENERIC_TIMEZONE=Asia/Seoul
- TZ=Asia/Seoul
- N8N_BASIC_AUTH_ACTIVE=false
- N8N_BLOCK_ENV_ACCESS_IN_NODE=false
- NODE_FUNCTION_ALLOW_BUILTIN=*
- NODE_FUNCTION_ALLOW_EXTERNAL=*
- N8N_DIAGNOSTICS_ENABLED=true
- NODE_TLS_REJECT_UNAUTHORIZED=0
volumes:
- n8n_data:/home/node/.n8n
- ./modules:/home/node/modules
- ./n8n_data:/home/node/data
- /etc/ssl/certs:/etc/ssl/certs
env_file:
- .env
volumes:
n8n_data:
external: true
- Operating system: