F7+Vue+Electron+Webpack usage of default modules of node (dns, net, fs, etc))

For internal needs, we decided to use an electron with F7. But when the application starts, default libraries like net, fs, dns are not found. Errors are reproduced like this.

...
Module not found: Error: Can't resolve 'net'
...

How to make them work with F7?

Did you create Electron project with F7-CLI? It has correct config for that, otherwise https://cordova.apache.org/docs/en/latest/guide/platforms/electron/#how-to-support-nodejs-and-electron-apis

Yes, I created Electron project with F7-cli v.3.2.1 (previous). The recommended link didnā€™t help.
But I found that configurations in webpack.config.js like below:

module.exports = {
...
 target: 'node',
 node: {
      net: 'empty',
      dns: 'empty',
      //required modules should be added here
   }
...

are solve my problem.

The given example works fine

const dns = require('dns');

dns.resolve4('framework7.io', (err, addresses) => {
   if (err) throw err;

   console.log(`addresses: ${JSON.stringify(addresses)}`);
   //=> addresses: ["104.18.47.65","104.18.46.65"]
});
1 Like