Installing node modules

Describe the problem/error/question

When trying to install a node module json2md, I keep getting error below.
According to the docs, the steps are straight forward, below is what I have done. Feels like I am probably missing something, yet I am unable to figure it out yet.
Any help / suggestions is greatly appreciated !

  1. Dockerfile
FROM n8nio/n8n:latest
USER root
RUN npm install --save json2md
USER node
  1. Have added this to environment in docker compose
- NODE_FUNCTION_ALLOW_EXTERNAL=*
  1. In a code node -
const json2md = require('json2md');

What is the error message (if any)?

ERROR: Cannot find module 'json2md' [line 1]

VMError: Cannot find module 'json2md'
    at LegacyResolver.resolveFull (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/resolver.js:126:9)
    at LegacyResolver.resolveFull (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/resolver.js:316:16)
    at LegacyResolver.resolveFull (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/resolver-compat.js:147:17)
    at LegacyResolver.resolve (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/resolver.js:121:15)
    at resolve (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/nodevm.js:317:21)
    at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/bridge.js:485:11)
    at requireImpl (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/setup-node-sandbox.js:90:19)
    at require (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/setup-node-sandbox.js:171:10)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:1:114
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:22:2

Information on your n8n setup

  • **n8n version: 1.14
  • **Database (default: SQLite): MySQL
  • **Running n8n via (Docker, npm, n8n cloud, desktop app): Docker Compose
  • **Operating system: Ubuntu

Hey @atomtr,

Try using the below and see if that helps.

FROM n8nio/n8n:latest
USER root
RUN npm install -g json2md
USER node
3 Likes

Perfect ! that worked, thanks @Jon ! so I need to install it globally.

Does it need to be installed as root ? Or will installing as node user be fine too ?

Hey @atomtr,

I would do it as root and swap the user back as sometimes a global package install can fail.

Neat, thanks a lot for the immediate responses !

1 Like

No problem, Happy flowgrammin’

1 Like

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