[Realm with Electron Using React] **Module** **not found** Error

Hey all, so I got it to work by doing the following.

In package.json, I have these scripts:

"scripts": {
    "start": "craco start",
    "build": "craco build",
    "electron-dev": "electron .",
    "electron": "wait-on tcp:3000 && electron .",
    "dev": "concurrently -k \"BROWSER=none npm start\" \"npm:electron\""
}

Of importance here is start—we use craco start instead of react-scripts start, which is the default.

My craco.config.js file now looks like this:

const nodeExternals = require("webpack-node-externals");
module.exports = {
  webpack: {
    configure: {
      resolve: {
        fallback: {
          "path": require.resolve("path-browserify"),
          "fs": false,
          "os": false
        }
      },
      target: "electron-renderer",
      externals: [
        nodeExternals({
          allowlist: [/webpack(\/.*)?/],
        }),
      ],
    },
  },
};

The fallback suggestion taken from @Yilmaz_Durmaz (thank you :pray:).

Combining realm and electron with React right now does not follow electron’s security recommendations—in particular, it doesn’t use ipcRenderer with Context Isolation. But unfortunately nodeIntegration: true and contextIsolation: false is the only way that works, but hopefully that will change in the near future.

Regardless, this was helpful—thanks!

1 Like