Manage import module in function

Hi all,
I'm making a function to parse the msg files of outlook because node-red-contrib-mail-parse works only with eml file.
I'm using the module @kenjiuno/msgreader so I installed the module with npm in the node-red folder and I wrote in the settings.js the row msgreader:require('@kenjiuno/msgreader') in functionGlobalContext and I import it in my function node with const MsgReader = global.get('msgreader');

In a normal script this module can be imported with import MsgReader from '@kenjiuno/msgreader' and then it need to create the object with const testMsg = new MsgReader(msgFileBuffer).
In function Node I can't use import so I use const MsgReader = global.get('msgreader'); but the function try the error "TypeError: MsgReader is not a constructor" at the row const testMsg = new MsgReader(msgFileBuffer).

MsgReader is an export of the module @kenjiuno/msgreader so I modified const MsgReader = global.get('msgreader'); in const MsgReader = global.get('msgreader').MsgReader but I have the same error;
I think the problem is that the contruct import-from is not correctly interpreted by the global.get('msgreader') but I didn't understant how I can to translate import MsgReader from '@kenjiuno/msgreader' for node function of nodered.
Can you help me?

When facing problems like this, best to raise an issue in the authors github:

Usage with node.js · Issue #5 · HiraokaHyperTools/msgreader (

with the suggested workaround from the author it works good.


Can you please share so that other people know what the resolution was?

Sure, my function is

const MsgReaderOrExports = global.get('msgreader');
const MsgReader = MsgReaderOrExports.default || MsgReaderOrExports;

const testMsg = new MsgReader(msg.payload);
const testMsgInfo = testMsg.getFileData();

msg.payload = testMsgInfo;
return msg;

in the row const testMsg = new MsgReader(msg.payload); msg.payload is the binary of the file that I extract with other function by the file received with a POST call

1 Like

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