Cannot find module 'xlsx' (or any)

Describe the problem/error/question

Hello, suddenly I am unable to load any module in code nodes, including those within the n8n package itself. I have gone through all sorts of forums, reinstalled both n8n and node, tried older versions, etc. For a day, the

set NODE_FUNCTION_ALLOW_BUILTIN=*
and
set NODE_FUNCTION_ALLOW_EXTERNAL=*
solved the problem. Now these do not work either. I wonder if these issues that I am experiencing derive from this problem I posted several weeks ago, which was not completely resolved. Below is the specific error I am receiving when trying to require('xlsx')

What is the error message (if any)?

  "errorMessage": "Cannot find module 'xlsx' [line 1]",
  "errorDescription": "VMError",
  "errorDetails": {},
  "n8nDetails": {
    "nodeName": "Code",
    "nodeType": "n8n-nodes-base.code",
    "nodeVersion": 2,
    "n8nVersion": "1.52.2 (Self Hosted)",
    "binaryDataMode": "default",
    "stackTrace": [
      "VMError: Cannot find module 'xlsx'",
      "    at Resolver.resolveFull (C:\\Users\\sherm\\AppData\\Roaming\\npm\\node_modules\\n8n\\node_modules\\@n8n\\vm2\\lib\\resolver.js:126:9)",
      "    at Resolver.resolve (C:\\Users\\sherm\\AppData\\Roaming\\npm\\node_modules\\n8n\\node_modules\\@n8n\\vm2\\lib\\resolver.js:121:15)",
      "    at resolve (C:\\Users\\sherm\\AppData\\Roaming\\npm\\node_modules\\n8n\\node_modules\\@n8n\\vm2\\lib\\nodevm.js:317:21)",
      "    at VM2 Wrapper.apply (C:\\Users\\sherm\\AppData\\Roaming\\npm\\node_modules\\n8n\\node_modules\\@n8n\\vm2\\lib/bridge.js:485:11)",
      "    at requireImpl (C:\\Users\\sherm\\AppData\\Roaming\\npm\\node_modules\\n8n\\node_modules\\@n8n\\vm2\\lib/setup-node-sandbox.js:90:19)",
      "    at require (C:\\Users\\sherm\\AppData\\Roaming\\npm\\node_modules\\n8n\\node_modules\\@n8n\\vm2\\lib/setup-node-sandbox.js:171:10)",
      "    at C:\\Users\\sherm\\AppData\\Roaming\\npm\\node_modules\\n8n\\node_modules\\n8n-nodes-base\\dist\\nodes\\Code:1:111",
      "    at C:\\Users\\sherm\\AppData\\Roaming\\npm\\node_modules\\n8n\\node_modules\\n8n-nodes-base\\dist\\nodes\\Code:18:2",
      "    at VM2 Wrapper.apply (C:\\Users\\sherm\\AppData\\Roaming\\npm\\node_modules\\n8n\\node_modules\\@n8n\\vm2\\lib\\bridge.js:485:11)",
      "    at NodeVM.run (C:\\Users\\sherm\\AppData\\Roaming\\npm\\node_modules\\n8n\\node_modules\\@n8n\\vm2\\lib\\nodevm.js:497:23)"
    ]
  }
}

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • **n8n version:1.52.2
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):npm
  • **Operating system:Windows 11
1 Like

Also, I get the same error when running a Docker container. The environment variables work in Docker, and they are necessary.

I seem to be able to solve it, for now, using a different syntax in PowerShell

$Env:NODE_FUNCTION_ALLOW_BUILTIN=’ * ’
$Env:NODE_FUNCTION_ALLOW_EXTERNAL=’ * ’

1 Like

Hey @Jonathan_Sherman,

It sounds like the issue here could be where the env options have not been set correctly, How you do this will vary depending on how you run n8n but we typically recommend using Docker as it leads to less issues and you won’t run into conflicts with globally installed npm packages or different node versions.

1 Like

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