n8n · troubleshooting · reproduced on n8n 2.41.4, 5 December 2026

n8n Code node: Module is disallowed

Module 'moment' is disallowed [line 1] means the Code node’s require() hit n8n’s allow-list, and the list is empty by default. Self-hosted n8n lets a Code node load a module only if you name it in an environment variable: NODE_FUNCTION_ALLOW_EXTERNAL for npm packages, NODE_FUNCTION_ALLOW_BUILTIN for Node’s own modules such as fs. Fix: set the variable for the module you need and recreate the n8n container (docker compose up -d). If the error then becomes Cannot find module, the module is allowed but not installed.

What we ran, and what each setting returned

Three one-line Code nodes: require('moment'), require('fs'), and a require of a package name that does not exist. All three ran under the first two configurations; under the wildcard we ran fs and the missing package:

Environment on the n8n containerrequire('moment')require('fs')A package that is not installed
Nothing set (the default)Module 'moment' is disallowedModule 'fs' is disallowedModule '…' is disallowed
NODE_FUNCTION_ALLOW_EXTERNAL=moment and NODE_FUNCTION_ALLOW_BUILTIN=fsRunsRunsModule '…' is disallowed
NODE_FUNCTION_ALLOW_EXTERNAL=*Not runModule 'fs' is disallowedCannot find module '…'

Run on 5 December 2026 with the official n8nio/n8n:2.41.4 image, workflows imported with n8n import:workflow and executed with n8n execute. Messages are copied from the terminal. This is the image’s default setup, where n8n starts the JavaScript task runner itself (internal mode). We did not run the external-mode setup with a separate runner container.

What the error looks like

With nothing configured, the execution fails on the first line of the Code node:

Module 'moment' is disallowed [line 1]
Error: Module 'moment' is disallowed
…
Execution was NOT successful. See log message for details.

The message is the same whether the module is an npm package, a Node built-in or a name that does not exist anywhere. “Disallowed” says nothing about whether the module is installed. It only says the name is not on the list. Once the name is allowed, a package that is missing fails differently:

Cannot find module 'cheerio-not-installed-xyz'
Require stack:
- /usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+task-runner…/dist/js-task-runner/require-resolver.js

The fixes

Allow the module by name

Add the variables to the n8n service and recreate the container. Both take a comma-separated list; n8n’s docs give NODE_FUNCTION_ALLOW_BUILTIN=crypto,fs and NODE_FUNCTION_ALLOW_EXTERNAL=moment,lodash as examples.

environment:
  - NODE_FUNCTION_ALLOW_EXTERNAL=moment
  - NODE_FUNCTION_ALLOW_BUILTIN=fs

With exactly these two set, our moment and fs workflows both finished with “Execution was successful”. Name the modules you use instead of allowing everything: a Code node that can load fs or child_process can read files and run commands in the container, and anyone who can edit a workflow can write that code.

A wildcard for npm packages does not cover built-ins

n8n’s docs show NODE_FUNCTION_ALLOW_BUILTIN=* to allow all built-in modules. The two lists are independent. We set only NODE_FUNCTION_ALLOW_EXTERNAL=* and require('fs') still returned Module 'fs' is disallowed. If the module in your error ships with Node.js, such as fs, path, crypto or url, it is a built-in, and it needs NODE_FUNCTION_ALLOW_BUILTIN. We tested fs only.

“Cannot find module”: allowed, but not installed

The allow-list does not install anything. moment ran for us because the 2.41.4 image already contains it. A package that is not in the image has to be added to the image the Code node runs in. For the external runner image, n8n’s task-runner docs describe extending n8nio/runners with a line such as RUN cd /opt/runners/task-runner-javascript && pnpm add moment uuid, and then allow-listing the packages as well. We have not built that image ourselves.

Still disallowed: the variable is on the wrong container

n8n’s docs carry this hint: “If n8n instance is setup with Task Runners, add the environment variables to the Task Runners instead to the main n8n node.” n8n’s own Postgres Compose file sets N8N_RUNNERS_MODE=external and runs a separate n8n-runner service from the n8nio/runners image. In that setup the docs put the allow-list in the runner’s n8n-task-runners.json, under env-overrides for the JavaScript runner, for example "NODE_FUNCTION_ALLOW_EXTERNAL": "moment,uuid". Check which mode you run before you add the variable a second time:

# is the variable in the running n8n container at all?
docker compose exec n8n printenv NODE_FUNCTION_ALLOW_EXTERNAL

# internal or external runners?
docker compose exec n8n printenv N8N_RUNNERS_MODE

An empty first answer means the variable never reached the container, for example because the service was restarted instead of recreated, or the line sits under the wrong service. An empty second answer means N8N_RUNNERS_MODE is not set, which is internal mode. The docs say internal mode is deprecated from n8n 3.0 and will be removed in a future version. We did not test 3.x.

On n8n Cloud

None of this applies. n8n’s docs: “If you use n8n Cloud, you can't import external npm modules.” Cloud makes two modules available, Node’s crypto and the moment package. For anything else, do the work in an HTTP Request node against an API, or self-host.

Related

The self-hosted n8n guide covers the Compose setup these variables go into. If n8n does not start at all after you edit the Compose file, see There was an error initializing DB. If a workflow that uses a Code node will not import, the n8n workflow JSON validator checks the file in your browser.

Sources and last verified

Reproduced on n8n 2.41.4 on 5 December 2026; the docs were read the same day. On that day n8n’s docs gave 3.4.4 as the current stable version. We did not re-run the reproduction on 3.x or in external mode, so wording may differ there. If n8n’s docs and this page disagree, n8n wins. Write to support@flowtemplates.app and we will re-verify.

Frequently asked questions

Why does the n8n Code node say “Module 'moment' is disallowed”?

Because self-hosted n8n blocks every require() in the Code node until you allow the module by name. n8n’s docs say external module support is disabled when the environment variable is not set. On n8n 2.41.4 with no variables set, require('moment'), require('fs') and a require of a package that does not exist all failed with the same “Module '…' is disallowed [line 1]”. Set NODE_FUNCTION_ALLOW_EXTERNAL=moment and recreate the container (docker compose up -d).

What is the difference between NODE_FUNCTION_ALLOW_BUILTIN and NODE_FUNCTION_ALLOW_EXTERNAL?

NODE_FUNCTION_ALLOW_BUILTIN is for modules that ship with Node.js, such as fs, crypto or path. NODE_FUNCTION_ALLOW_EXTERNAL is for npm packages, which n8n’s docs describe as external modules sourced from the n8n/node_modules directory. They are separate lists. When we set NODE_FUNCTION_ALLOW_EXTERNAL=* on n8n 2.41.4, require('fs') was still refused with “Module 'fs' is disallowed”.

I allowed the module and now it says “Cannot find module”. What changed?

You are past the allow-list and the package is not installed where the Code node runs. Allowing a module does not install it. With NODE_FUNCTION_ALLOW_EXTERNAL=* we required a package that was not in the image and the error changed from “is disallowed” to “Cannot find module”. moment worked for us without installing anything because it is already in the n8n 2.41.4 image.

I set the variables and still get “is disallowed”. Why?

Two things to check. First, that the variable reached the running container: docker compose exec n8n printenv NODE_FUNCTION_ALLOW_EXTERNAL. Second, where your Code node runs. n8n’s docs say that if the instance is set up with task runners, the variables go on the task runners instead of the main n8n node. n8n’s own Postgres Compose file runs in external mode with a separate n8n-runner container, and there the docs set the allow-list in the runner’s n8n-task-runners.json. We reproduced only the default internal mode, where the variable on the n8n container was enough.

Can I use npm modules in the Code node on n8n Cloud?

No. n8n’s docs say that on n8n Cloud you cannot import external npm modules, and that n8n makes two modules available: Node’s crypto module and the moment package. Allowing other modules is a self-hosting feature.