Can't use Node.js modules, even though NODE_FUNCTION_ALLOW_BUILTIN=*

Describe the problem/error/question

I’m self hosting n8n on Coolify and have environment variables set:
NODE_FUNCTION_ALLOW_EXTERNAL=*
NODE_FUNCTION_ALLOW_BUILTIN=*
N8N_DISABLE_FUNCTION_MODULE_ISOLATION=true

I’ve tested this code block:

try {
  const dns = require('dns');
} catch (e) {
  return [{ json: { error: e.message } }];
}

What is the error message (if any)?

I’m getting this error:


[ { "error":  "Cannot find module 'dns'" } ]

Information on your n8n setup

  • n8n version: 1.104.1
  • Database (default: SQLite): postgres + redis
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Coolify with Docker
  • Operating system: Ubuntu 22.04

Did u install the package on the server inside the container?

dns is a default module, it doesn’t require installing.

1 Like

NODE_FUNCTION_ALLOW_BUILTIN=*

is the only thing I had to do for dns to become available. Did you restart the container after introducing the new variable?

I did. Since I’m running Coolify, I added the environment variables in that section, then pulled the latest and restarted. Still no dice.


This is my n8n setup in Coolify. Maybe that will shed some light?

I see you are running in a queue mode, do you workers inherit the same set of env variables?

Yes they should. Just to test, I set execution mode to regular, and I’m still unable to pull in the modules.

Out of curiosity - if you add an Execute node and run this:

node -p "require('module').builtinModules"

or one of the following:

node -p "require('module').builtinModules.includes('dns')"
node -e "require('dns'); console.log('dns module is available');"

What do you see?

Well, the modules are there…

[
  {
    "stdout": "[
    '_http_agent',
    '_http_client',
    '_http_common',
    '_http_incoming',
    '_http_outgoing',
    '_http_server',
    '_stream_duplex',
    '_stream_passthrough',
    '_stream_readable',
    '_stream_transform',
    '_stream_wrap',
    '_stream_writable',
    '_tls_common',
    '_tls_wrap',
    'assert',
    'assert/strict',
    'async_hooks',
    'buffer',
    'child_process',
    'cluster',
    'console',
    'constants',
    'crypto',
    'dgram',
    'diagnostics_channel',
    'dns',
    'dns/promises',
    'domain',
    'events',
    'fs',
    'fs/promises',
    'http',
    'http2',
    'https',
    'inspector',
    'inspector/promises',
    'module',
    'net',
    'os',
    'path',
    'path/posix',
    'path/win32',
    'perf_hooks',
    'process',
    'punycode',
    'querystring',
    'readline',
    'readline/promises',
    'repl',
    'stream',
    'stream/consumers',
    'stream/promises',
    'stream/web',
    'string_decoder',
    'sys',
    'timers',
    'timers/promises',
    'tls',
    'trace_events',
    'tty',
    'url',
    'util',
    'util/types',
    'v8',
    'vm',
    'wasi',
    'worker_threads',
    'zlib'
    ]"
  }
]

How about (also from the Execute Node):

node -e "console.log(process.env.NODE_FUNCTION_ALLOW_BUILTIN)"
2 Likes

Ah, there it is… looks like it’s not pulling in the Coolify environment variables

[
  {
    "exitCode": 0,
    "stderr": "",
    "stdout": "undefined"
  }
]

So if I edit my docker compose, can I redploy without losing everything? I’d hate to nuke all the live workflows…

BOOM! Fixed. Using Coolify, the environment variables aren’t carrying through. So I edited the docker compose, and woot, it worked!

Thanks for the help!

3 Likes

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