External on node function are not recognized by Task Runner

Describe the problem/error/question

The addition of environment variable N8N_RUNNERS_ENABLED set to true leads to error below. Variable NODE_FUNCTION_ALLOW_EXTERNAL is set to moment,lodash,moment-with-locales.

What is the error message (if any)?

[Task Runner]: Task runner failed to start {
  error: Error: Cannot find module 'moment-with-locales'
  Require stack:
  - /usr/local/lib/node_modules/n8n/node_modules/@n8n/task-runner/dist/js-task-runner/js-task-runner.js
  - /usr/local/lib/node_modules/n8n/node_modules/@n8n/task-runner/dist/start.js
      at Module._resolveFilename (node:internal/modules/cjs/loader:1225:15)
      at Module._load (node:internal/modules/cjs/loader:1051:27)
      at Module.require (node:internal/modules/cjs/loader:1311:19)
      at require (node:internal/modules/helpers:179:18)
      at JsTaskRunner.preventPrototypePollution (/usr/local/lib/node_modules/n8n/node_modules/@n8n/task-runner/dist/js-task-runner/js-task-runner.js:86:17)
      at new JsTaskRunner (/usr/local/lib/node_modules/n8n/node_modules/@n8n/task-runner/dist/js-task-runner/js-task-runner.js:81:14)
      at start (/usr/local/lib/node_modules/n8n/node_modules/@n8n/task-runner/dist/start.js:85:14)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
      '/usr/local/lib/node_modules/n8n/node_modules/@n8n/task-runner/dist/js-task-runner/js-task-runner.js',
      '/usr/local/lib/node_modules/n8n/node_modules/@n8n/task-runner/dist/start.js'
    ]
  }
}

Share the output returned by the last node

Information on your n8n setup

  • n8nVersion: 1.82.0
  • platform: docker (self-hosted)
  • nodeJsVersion: 20.18.3
  • database: postgres
  • executionMode: regular
  • concurrency: -1
  • license: enterprise (production)

I believe you also have to pre install the modules for them to be imported. Did you install them within the docker container?

This isn’t mine but seems like a good guide:

Geez, the environment variable NODE_FUNCTION_ALLOW_EXTERNAL should handle that…

No, it does not handle installation of the packages, just importing.

They might be able to be installed server level and mapped to n8n/node_modules as well, but you may encounter issues with different architectures and versions.

Did that fix it for you? Would appreciate marking as solution if so. :slight_smile:

This PR eems to address precisely this issue I mention. Please, make sure to check and confirm. :smile:

I didn’t dig too deeply, but that may help but isn’t that helpful. Seems it’s only to change the dir for modules, which would still be looking in the docker tho unless mapped via volumes.