Need help with loading custom module javascript-time-ago

I need help loading a custom node module which I was perviosuly able to load in global node_module directory.

I see the module in ~/.n8n/nodes/node_modules/javascript-time-ago but my function node is not able to load it in version 1. I followed the v1.0 migration guide, but my function node errors out on

const TimeAgo = require(“javascript-time-ago”);

Cannot find module ‘javascript-time-ago’ [line 1]

Hi @roozbehk, I am sorry for the trouble. I could only get this to work on npm by making node modules available under /usr/local/lib/node_modules, for example like so in a docker compose file:

      - './data:/home/node/.n8n'
      - '~/.n8n/nodes/node_modules/javascript-time-ago:/usr/local/lib/node_modules/javascript-time-ago'
      - '~/.n8n/nodes/node_modules/relative-time-format:/usr/local/lib/node_modules/relative-time-format'
      - '5678:5678'

Afterwards, I could require such modules as expected:

That said, perhaps there is an easier way. @netroy can you confirm what the proper approach would be here? Or in other words, how would one one make all npm packages in ~/.n8n/nodes/node_modules available to n8n?

1 Like

Thank you @MutedJam , your workaround solution worked as expected and the node module loaded. I believe this soltuon should sustain n8n version upgrades so I have no issues mouting the node modules needed into the /usr/local/lib/node_modules directory moving forward.

1 Like

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