TypeError: _crypto.randomBytes is not a function in electron

I am trying to use node-forge library for salt generation in electron , node-forge internally uses native ‘crypto’ , but i keep getting this error

I am using react with electron , the code is in a .jsx file and not in main.js (main process) of electron

TypeError: _crypto.randomBytes is not a function
```'

This happens only in electron , in browser it works fine .

The error occurs when i run this 

let a=forge.random.getBytesSync(128 / 8);

[forge internally calls]
ctx.seedFileSync = function(needed) {
return _crypto.randomBytes(needed).toString();
};



tried doing this in render process 

window.require('crypto')  : It worked,but stopped working.Cannot remember if i changed something