I’m having trouble accessing the built‐in Node.js module fs in a Code node. Despite setting the environment variable to allow fs via my Docker setup—and even trying to extend the official image with a custom Dockerfile—I still get the error: Cannot find module ‘fs’
VMError: Cannot find module ‘fs’
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)
… (stack trace continues)
const fs = require('fs');
const filePath = `/path/to/${$input.first().json.fileName}.md`;
const fileExists = fs.existsSync(filePath);
return [{ exists: fileExists }];
• | n8n version: 1.88.0 (Self Hosted) | |
---|---|---|
• | Database (default: SQLite): SQLite | |
• | n8n EXECUTIONS_PROCESS setting (default: own, main): own | |
• | Running n8n via (Docker, npm, n8n cloud, desktop app): Docker (using an ARM64 container) | |
• | Operating system: Host OS is macOS; container is Linux/arm64 |
I initially ran the official image with:
docker run --platform linux/arm64 -it --rm --name n8n -p 5678:5678 \
-e "NODE_FUNCTION_ALLOW_BUILTIN_MODULES=fs" \
-v ~/n8n_data:/home/node/.n8n \
-v /Users/REDACTED/data:/data \
docker.n8n.io/n8nio/n8n:1.88.0
I verified via inspection that the environment variable appears in the container’s “Env” array.
When I still had the error I created a custom image build with this Dockerfile
FROM docker.n8n.io/n8nio/n8n:1.88.0
ENV NODE_FUNCTION_ALLOW_BUILTIN_MODULES=fs
But it didn’t solve the issue - I’m a bit stuck now since everything I’ve read tells me things SHOULD be working…