Cannot read properties of null (reading 'allNodes')

I have imported "node-red" , initialized it and then used below addFlow function,

RED.start().then(() => {
RED.runtime.flows.addFlow({ flow: Flow, req: {} });
});

still it is throwing error as,

if (activeFlowConfig.allNodes[node.id]) {
^
TypeError: Cannot read properties of null (reading 'allNodes')

Can you please help on this to resolve the issue?