12

What is the easy way to add react dev tool to electron window? I try add the extension hash

BrowserWindow.addDevToolsExtension('path/to/extension/ade2343nd23k234bdb').15.01

But when the extension update, I had to manually update the string in main.js. I'm looking for a better way.

angry kiwi
  • 10,730
  • 26
  • 115
  • 161

5 Answers5

19

Here is a Solution for Electron <= 1.2.1 version

1- In your app folder

npm install --save-dev electron-react-devtools

2- Open your electron app, click on (view/toggle developer tools). In the console tab insert the following code and hit enter:

 require('electron-react-devtools').install()

3- Reload/refresh your electron app page and you'll see the react dev tools appear.

4- Done!


See screen shots bellow

Paste/type code on console tab

hit enter

react dev tools enabled

Jonca33
  • 3,333
  • 7
  • 25
  • 35
  • 1
    Note that this method only installs the react devtools for the current session; you have to do this every time you launch your application. – Zentryn May 05 '19 at 16:26
  • 3
    Package got abandoned, here's my take: https://www.npmjs.com/package/react-devtools-electron – Dimitar Nestorov Aug 21 '19 at 15:54
  • @Zentryn you are right. Have you found a way to permanently have access to the tools without re-running this command every time we launch the app? – sediq khan Oct 07 '20 at 08:54
  • @DimitarNestorov attempting to install your package gets `TypeError: Cannot read property 'isReady' of undefined` – dWitty Aug 04 '21 at 12:33
  • 1
    @dWitty Electron updated the internals a while ago and I haven't had time to fix it. Some people are reporting that they can't get it to work (not using my library) even with the latest version of electron: https://github.com/electron/electron/issues/23662 – Dimitar Nestorov Aug 13 '21 at 14:29
  • `React DevTools can only be installed from an renderer process.` i see this when i try to execute `require('electron-react-devtools').install()` – blogbydev Oct 26 '21 at 05:07
9

You can add react devtools directly from your main.js file like this

const installExtensions = async () => {
  const installer = require('electron-devtools-installer')
  const forceDownload = !!process.env.UPGRADE_EXTENSIONS
  const extensions = [
    'REACT_DEVELOPER_TOOLS',
    'REDUX_DEVTOOLS',
    'DEVTRON'
  ]

  return Promise
    .all(extensions.map(name => installer.default(installer[name], forceDownload)))
    .catch(console.log)
}

app.on('ready', async () => {
  if (dev && process.argv.indexOf('--noDevServer') === -1) {
    await installExtensions()
  }
  createWindow()
})
Pushkin
  • 3,336
  • 1
  • 17
  • 30
2

addDevToolsExtension is not an instance method, so you need to call BrowserWindow.addDevToolsExtension('path/to/extension').

Vadim Macagon
  • 14,463
  • 2
  • 52
  • 45
0

Below solution worked for me (https://github.com/MarshallOfSound/electron-devtools-installer#usage) -

npm install electron-devtools-installer --save-dev 
or 
yarn add electron-devtools-installer -D
import installExtension, { REDUX_DEVTOOLS } from 'electron-devtools-installer';
// Or if you can not use ES6 imports
/**
const { default: installExtension, REACT_DEVELOPER_TOOLS } = require('electron-devtools-installer');
*/
const { app } = require('electron');

app.whenReady().then(() => {
    installExtension(REDUX_DEVTOOLS)
        .then((name) => console.log(`Added Extension:  ${name}`))
        .catch((err) => console.log('An error occurred: ', err));
});
Chetan Gawai
  • 2,361
  • 1
  • 25
  • 36
-1

If you see a blank component when launching react-devtools, it's probably because you've installed the package globally as it is recommended in the react-native docs, in the debugging section. What's happening is it doesn't get connected to your app, because it's not your app-specific.

You need to install it locally.

npm install --save-dev react-devtools

or

yarn add -D react-devtools
yavnelf
  • 169
  • 1
  • 2
  • 12