'Issues with created external with webpack toghether with firebase and electron

I am trying to build an application using Electron and React I upgraded my firebase from v8 to v9 and then issues appeared.

Webpack bundles succesfully. This is the compilation outcome

asset app.js 5.92 MiB [emitted] (name: main)
runtime modules 1.36 KiB 6 modules
modules by path ./ 2.19 MiB
  modules by path ./node_modules/ 2.14 MiB 81 modules
  modules by path ./src/js/ 48.1 KiB 22 modules
asset modules 4.4 KiB
  data:image/svg+xml,%3csvg xmlns=%27.. 281 bytes [built] [code generated]
  data:image/svg+xml,%3csvg xmlns=%27.. 279 bytes [built] [code generated]
  data:image/svg+xml,%3csvg xmlns=%27.. 161 bytes [built] [code generated]
  data:image/svg+xml,%3csvg xmlns=%27.. 271 bytes [built] [code generated]
  data:image/svg+xml,%3csvg xmlns=%27.. 181 bytes [built] [code generated]
  data:image/svg+xml,%3csvg xmlns=%27.. 165 bytes [built] [code generated]
  data:image/svg+xml,%3csvg xmlns=%27.. 161 bytes [built] [code generated]
  + 9 modules
external "util" 42 bytes [built] [code generated]
external "crypto" 42 bytes [built] [code generated]
webpack 5.72.1 compiled successfully in 1706 ms

This is the webpack config

const path = require('path');
const Dotenv = require('dotenv-webpack')

module.exports = {
  mode: 'development',
  entry: './src/js/index.js',
  devtool: 'inline-source-map',
  target: 'electron-renderer',
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: [[
              '@babel/preset-env', {
                targets: {
                  esmodules: true
                }
              }],
              '@babel/preset-react']
          }
        }
      },
      {
        test: [/\.s[ac]ss$/i, /\.css$/i],
        use: [
          // Creates `style` nodes from JS strings
          'style-loader',
          // Translates CSS into CommonJS
          'css-loader',
          // Compiles Sass to CSS
          'sass-loader',
        ],
      }
    ]
  },
  plugins: [
    new Dotenv()
  ],
  resolve: {
    extensions: ['.js'],
  },
  output: {
    filename: 'app.js',
    path: path.resolve(__dirname, 'build', 'js'),
  },
};

The issue comes when starting the electron process and it says

Uncaught ReferenceError: require is not defined
    at Object.util (app.js:40113:1)
    at __webpack_require__ (app.js:52195:42)
    at Module../node_modules/@firebase/firestore/dist/lite/index.node.mjs (app.js:41684:62)
    at __webpack_require__ (app.js:52195:42)
    at Module../node_modules/firebase/firestore/lite/dist/index.mjs (app.js:51819:82)
    at __webpack_require__ (app.js:52195:42)
    at Module../src/js/db/repos/ChatRepo.js (app.js:2332:81)
    at __webpack_require__ (app.js:52195:42)
    at Module../src/js/api/chatsApi.js (app.js:1915:76)
    at __webpack_require__ (app.js:52195:42)

The issue seems to be that require appears at util

module.exports = require("util");

Now the util seems to be generated but require still apears and i do not understand what is happening

Can someone please help, or tell me if this is an issue with firebase?

Thank you



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source