Keep getting "Cannot find module 'xlsx' " on production execution

Describe the problem/error/question

I host n8n on railway app and use a custom docker file as suggested here - The definitive guide to custom NPM modules for self-hosted instances - #2 by Jon
When I run the code node in test mode, everything works fine. However on production execution I get VMerror

What is the error message (if any)?

Please share your workflow

{
  "errorMessage": "Cannot find module 'xlsx' [line 1]",
  "errorDescription": "VMError",
  "errorDetails": {},
  "n8nDetails": {
    "nodeName": "Code",
    "nodeType": "n8n-nodes-base.code",
    "nodeVersion": 2,
    "n8nVersion": "1.72.1 (Self Hosted)",
    "binaryDataMode": "default",
    "stackTrace": [
      "VMError: Cannot find module 'xlsx'",
      "    at Resolver.resolveFull (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/resolver.js:126:9)",
      "    at Resolver.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:490: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:111",
      "    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:238:2",
      "    at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/bridge.js:490:11)",
      "    at NodeVM.run (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/nodevm.js:497:23)"
    ]
  }
}

Information on your n8n setup

  • **n8n version:1.72.1 (Self Hosted)
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):Docker
  • Operating system:

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey @nk123,

Are you running n8n in queue mode? It sounds like you could be and that your workers don’t have the npm package installed.

You are right, my workers didn’t have the package. Fixed it now. Thank you :slight_smile:

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