[v0.169.0] VMError: Cannot find module

Describe the issue/error/question

In the function nodes, I often use the npm module ‘faker’ (v5.5.3, the functional one) by including it in my Dockerfile, like so:

RUN npm install -g [email protected]

Now, in my n8n prod instance (v0.170.0), i’m receiving the below mentioned error.
But, in my n8n dev instance (v0.168.1), it’s working fine.

Apparently, something changed between these two versions which has caused this issue.

What is the error message (if any)?

VMError: Cannot find module '/usr/local/lib/node_modules/faker'
    at LegacyResolver.loadAsPackage (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/resolver.js:427:11)
    at LegacyResolver.loadAsDirectory (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/resolver.js:439:15)
    at LegacyResolver.loadNodeModules (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/resolver.js:457:13)
    at LegacyResolver.resolveFull (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/resolver.js:310:12)
    at LegacyResolver.resolveFull (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/resolver-compat.js:100:17)
    at LegacyResolver.resolve (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/resolver.js:105:15)
    at ReadOnlyHandler.apply (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/bridge.js:479:11)
    at requireImpl (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/setup-node-sandbox.js:84:28)
    at require (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/setup-node-sandbox.js:165:10)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Function:1:112
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Function:35:2
    at BaseHandler.apply (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/bridge.js:479:11)
    at NodeVM.run (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/nodevm.js:425:23)
    at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Function/Function.node.js:96:31)
    at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/src/Workflow.js:526:37)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/WorkflowExecute.js:451:62
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Please share the workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 0.170.0
  • Database you’re using (default: SQLite): Postgres
  • Running n8n with the execution process [own(default), main]: main
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: Docker

Any idea about this?

Hey @shrey-42,

I have not tested it but looking at that error it looks like the package has not installed and Node is coming back to say it can’t find it.

Can you access the container and check to see if that faker directory exists?