Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly set up material-ui with electron-react-boilerplate

I'm having issues with material-ui (v4.9.5) library running with electron-react-boilerplate. To reproduce:

  1. follow the installation tutorial
  2. yarn add @material-ui/core
  3. add some widgets from the library:
diff --git a/app/components/Home.tsx b/app/components/Home.tsx
index 20748ab..f4f9a21 100644
--- a/app/components/Home.tsx
+++ b/app/components/Home.tsx
@@ -1,11 +1,13 @@
 import React from 'react';
 import { Link } from 'react-router-dom';
+import { Button } from '@material-ui/core';
 import routes from '../constants/routes.json';
 import styles from './Home.css';

 export default function Home() {
   return (
     <div className={styles.container} data-tid="container">
+      <Button>Hello</Button>
       <h2>Home</h2>
       <Link to={routes.COUNTER}>to Counter</Link>
     </div>

Now everything works great when you run yarn dev. However, yarn start produces:

init.ts:204 Unable to load preload script: /home/vasniktel/boiler-test/app/dist/renderer.prod.js
(anonymous) @ init.ts:204
init.ts:205 TypeError: Cannot use 'in' operator to search for 'ontouchstart' in null
    at Module../app/index.tsx (/home/vasniktel/boiler-test/app/dist/renderer.prod.js:2)
    at n (/home/vasniktel/boiler-test/app/dist/renderer.prod.js:2)
    at module.exports../app/app.global.css (/home/vasniktel/boiler-test/app/dist/renderer.prod.js:2)
    at Object.<anonymous> (/home/vasniktel/boiler-test/app/dist/renderer.prod.js:2)
    at Object.<anonymous> (/home/vasniktel/boiler-test/app/dist/renderer.prod.js:3)
    at Module._compile (internal/modules/cjs/loader.js:880)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:892)
    at Module.load (internal/modules/cjs/loader.js:735)
    at Module._load (internal/modules/cjs/loader.js:648)
    at Module._load (electron/js2c/asar.js:717)
(anonymous) @ init.ts:205

Is there any way to fix this?

like image 414
Vasniktel Avatar asked Mar 01 '20 09:03

Vasniktel


People also ask

Is electron react boilerplate good?

Going by raw numbers, electron-react-boilerplate has won hearts and minds. With more than 16,000 stars on GitHub, it's currently the most popular boilerplate choice. It combines TypeScript, Babel, webpack, and eslint, handling Electron's compile and package operations by utilizing electron-builder.

What is electron react boilerplate?

The Create-electron-app boilerplate is a combination of Electron, React, and Redux, with the build and package scripts, signifying the ability to initiate a project without spending a lot of time in the initial configurations.

What is electron react?

What is Electron? Electron is a cross-platform desktop application framework. It is used to build desktop applications with the JavaScript language. It's definitely also possible to use JavaScript frameworks like React and Vue to build desktop applications with Electron.


1 Answers

It seems that removal of these lines from the main.dev.ts file solves the problem:

@@ -58,14 +58,9 @@ const createWindow = async () => {
     show: false,
     width: 1024,
     height: 728,
-    webPreferences:
-      process.env.NODE_ENV === 'development' || process.env.E2E_BUILD === 'true'
-        ? {
-            nodeIntegration: true
-          }
-        : {
-            preload: path.join(__dirname, 'dist/renderer.prod.js')
-          }
+    webPreferences: {
+      nodeIntegration: true
+    }
   });
like image 186
Vasniktel Avatar answered Oct 23 '22 04:10

Vasniktel