Cannot find module 'url'

Hi after updating n8n from 1.6.1 to 1.16.0 i have the following error in the code node:

VMError: Cannot find module 'url'
    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:110
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:7:2

i run n8n in docker with worker nodes and the var:
NODE_FUNCTION_ALLOW_EXTERNAL is set to: crypto,url

Hey @Benedikt_Bohm,

Have you installed the url package in your n8n container?

Yes tested it via connecting to the console and executed that node script directly in the container:

const url = require('url');

try {
    const myURL = new URL('https://example.com');
    console.log(`Das URL-Modul funktioniert: ${myURL.href}`);
} catch (error) {
    console.error(`Fehler beim Verwenden des URL-Moduls: ${error.message}`);
}

Hey @Benedikt_Bohm,

What happens if you set NODE_FUNCTION_ALLOW_EXTERNAL to * does that work?

Doesnt work…

Interesting, I have never added url to my n8n instance but with the above setting I am able to use it without issue.

When you set the environment variable did you remember to stop then start the instances rather than just doing a restart? I noticed you mentioned workers as well do you see this when running the workflow in the UI or when the workflow is being triggered by another flow?

I did the update process as follow:

  • stopping all containers
  • backup DB
  • adjust the settings to pull the new image 1.16.0
  • run all containers (main, webhook, worker) with the new version

the crypto and url module cannot be found from n8n.
tested with:

  • manually triggered the code node: error
  • with webhook-test: error
  • with webhook: error
  • connected in the docker container via console and runned the script above: working

the only difference from the n8n deployment bevore is that is running on a different url

That should do the job, Could you try setting NODE_FUNCTION_ALLOW_INTERNAL to * as well?

Also doesnt work.
Checked the env directly in the container and both are available

Hey @Benedikt_Bohm,

That is very unusual, Are you using our normal docker images or a custom image? I have just given it a very quick test with a new n8n container on a Digital Ocean droplet and it is working as expected there as well.

Can you share how you are running n8n and what env options you have set and I can see if we can reproduce it.

Compose files:

Main:

version: "3.9"
services:
  redis:
    image: bitnami/redis:latest
    restart: unless-stopped
    ports:
      - 6579:6379
    environment:
      REDIS_PASSWORD: ${REDIS_PASSWORD}
  n8n-main:
    image: n8nio/n8n:1.16.0
    restart: unless-stopped
    ports:
      - 6678:6678
    env_file:
      - stack.env
    command: start

Webhook:

version: "3.9"
services:
  n8n-webhook:
    image: n8nio/n8n:1.16.0
    restart: unless-stopped
    ports:
      - 6680:6678
    env_file:
      - stack.env
    command: webhook

Worker:

version: "3.9"
services:
  n8n-worker1:
    image: n8nio/n8n:1.16.0
    restart: unless-stopped
    env_file:
      - stack.env
    command: worker --concurrency=20

ENVS
main:

DB_TYPE=postgresdb
DB_POSTGRESDB_DATABASE=
DB_POSTGRESDB_HOST=
DB_POSTGRESDB_PORT=5432
DB_POSTGRESDB_USER=n8n
DB_POSTGRESDB_PASSWORD=
N8N_HOST=api.domain.com
N8N_PROTOCOL=https
N8N_PORT=6678
VUE_APP_URL_BASE_API=https://api.domain.com/
N8N_ENCRYPTION_KEY=
EXECUTIONS_MODE=queue
QUEUE_BULL_REDIS_HOST=api.domain.com
QUEUE_BULL_REDIS_PORT=6579
QUEUE_BULL_REDIS_PASSWORD=
WEBHOOK_URL=https://api.domain.com
EXECUTIONS_DATA_PRUNE=true
EXECUTIONS_DATA_MAX_AGE=7
REDIS_PASSWORD=
N8N_LOG_LEVEL=debug
N8N_PUSH_BACKEND=sse
NODE_FUNCTION_ALLOW_EXTERNAL=*
N8N_PAYLOAD_SIZE_MAX=512MB
NODE_OPTIONS=--max-old-space-size=5120 --max-semi-space-size=5120
EXECUTIONS_DATA_PRUNE_MAX_COUNT=5000
EXECUTIONS_DATA_SAVE_ON_ERROR=all
EXECUTIONS_DATA_SAVE_ON_SUCCESS=none
EXECUTIONS_DATA_SAVE_ON_PROGRESS=none
N8N_DISABLE_PRODUCTION_MAIN_PROCESS=true
NODE_FUNCTION_ALLOW_INTERNAL=*

Webhook:

DB_TYPE=postgresdb
DB_POSTGRESDB_DATABASE=
DB_POSTGRESDB_HOST=api.domain.com
DB_POSTGRESDB_PORT=5432
DB_POSTGRESDB_USER=n8n
DB_POSTGRESDB_PASSWORD=
N8N_HOST=api.domain.com
N8N_PROTOCOL=https
N8N_PORT=6678
VUE_APP_URL_BASE_API=https://api.domain.com/
N8N_ENCRYPTION_KEY=
EXECUTIONS_MODE=queue
QUEUE_BULL_REDIS_HOST=
QUEUE_BULL_REDIS_PORT=6579
QUEUE_BULL_REDIS_PASSWORD=
WEBHOOK_URL=https://api.domain.com
EXECUTIONS_DATA_PRUNE=true
EXECUTIONS_DATA_MAX_AGE=48
REDIS_PASSWORD=
N8N_LOG_LEVEL=debug
N8N_PUSH_BACKEND=sse
NODE_FUNCTION_ALLOW_EXTERNAL=*
N8N_PAYLOAD_SIZE_MAX=512MB
NODE_OPTIONS=--max-old-space-size=5120 --max-semi-space-size=5120
EXECUTIONS_DATA_PRUNE_MAX_COUNT=5000
EXECUTIONS_DATA_SAVE_ON_ERROR=all
EXECUTIONS_DATA_SAVE_ON_SUCCESS=none
EXECUTIONS_DATA_SAVE_ON_PROGRESS=none
NODE_FUNCTION_ALLOW_INTERNAL=*

worker:

DB_TYPE=postgresdb
DB_POSTGRESDB_DATABASE=
DB_POSTGRESDB_HOST=api.domain.com
DB_POSTGRESDB_PORT=5432
DB_POSTGRESDB_USER=n8n
DB_POSTGRESDB_PASSWORD=
N8N_ENCRYPTION_KEY=
EXECUTIONS_MODE=queue
QUEUE_BULL_REDIS_HOST=
QUEUE_BULL_REDIS_PORT=6579
QUEUE_BULL_REDIS_PASSWORD=
N8N_PAYLOAD_SIZE_MAX=512MB
NODE_OPTIONS=--max-old-space-size=5120 --max-semi-space-size=5120
EXECUTIONS_DATA_PRUNE_MAX_COUNT=5000
EXECUTIONS_DATA_SAVE_ON_ERROR=all
EXECUTIONS_DATA_SAVE_ON_SUCCESS=none
EXECUTIONS_DATA_SAVE_ON_PROGRESS=none
NODE_FUNCTION_ALLOW_EXTERNAL=*
NODE_FUNCTION_ALLOW_INTERNAL=*
1 Like

Can you please try replacing NODE_FUNCTION_ALLOW_INTERNAL=* with NODE_FUNCTION_ALLOW_BUILTIN=* ?

That will be it, There is no internal not sure where I got that from.

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