Notification error in electron-react app with webpack

Viewed 80

I am getting error for below react code in electron app.

import React from 'react';
import Button from '@material-ui/core/Button';
import { Notification } from 'electron';

export default function App() {

  function showNotification () {
    const notification = {
      title: 'Basic Notification',
      body: 'Notification from the Main process'
    }
    new Notification(notification).show()
  }

  return (
    <>
      <Button variant="contained" color="secondary" onClick={showNotification}>
        Primary
      </Button>
    </>
  )
}

When i am clicking button, its giving error

App.jsx:14 Uncaught TypeError: electron__WEBPACK_IMPORTED_MODULE_2__.Notification is not a constructor
    at showNotification (App.jsx:14)
    at HTMLUnknownElement.callCallback (react-dom.development.js:189)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:238)
    at invokeGuardedCallback (react-dom.development.js:293)
    at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:307)
    at executeDispatch (react-dom.development.js:390)
    at executeDispatchesInOrder (react-dom.development.js:415)
    at executeDispatchesAndRelease (react-dom.development.js:3279)
    at executeDispatchesAndReleaseTopLevel (react-dom.development.js:3288)
    at forEachAccumulated (react-dom.development.js:3260)
showNotification @ App.jsx:14

i think its issue with webpack configuration, can anyone help me to fix this issue.

0 Answers
Related