sindresorhus / electron-is-dev

Check if Electron is running in development
MIT License
427 stars 34 forks source link

electron.remote module deprecation warning #24

Closed DRocksCoding closed 3 years ago

DRocksCoding commented 4 years ago

In a browser window without enableRemoteModule:true, this line warns about the usage of deprecated remote module with electron 9.1.0.

const app = electron.app || electron.remote.app;

Would it be a good thing to get rid of remote usage?

brandly commented 4 years ago

electron 10 was released recently, and this is now throwing!

Uncaught TypeError: Cannot read property 'app' of undefined
    at Object.<anonymous> (.../Lax/node_modules/electron-is-dev/index.js:4)
    at Object.<anonymous> (.../Lax/node_modules/electron-is-dev/index.js:11)
    at Module._compile (internal/modules/cjs/loader.js:1145)
    at Module._compile (.../Lax/node_modules/pirates/lib/index.js:99)
    at Module._extensions..js (internal/modules/cjs/loader.js:1166)
    at Object.newLoader [as .js] (.../Lax/node_modules/pirates/lib/index.js:104)
    at Module.load (internal/modules/cjs/loader.js:981)
    at Module._load (internal/modules/cjs/loader.js:881)
    at Function.Module._load (electron/js2c/asar.js:769)
    at Module.require (internal/modules/cjs/loader.js:1023)

which links through to here:

const app = electron.app || electron.remote.app;
                                            ^

hopefully this gets fixed and bubbles up to electron-util

smithalan92 commented 4 years ago

Getting rid of the remote usage would mean this could only be used in main process modules ( theres not alternative for app.isPackaged ).

The remote module is not being depreciated ( not notice in docs, nor any warnings in Electron 10.1.1 ) so setting enableRemoteModule:true in your web preferences is the solution.

alex-drocks commented 4 years ago

same here I jsut posted that in electron-context-menu:

https://github.com/sindresorhus/electron-context-menu/issues/117#issue-690324541

stevenroussey-privicy commented 4 years ago

remote object is deprecated and will be completely removed in Electron 14.

stevenroussey-privicy commented 4 years ago

Reference: https://github.com/electron/electron/issues/21408

stevenroussey-privicy commented 4 years ago

PS: what i did was the following, though it is not as elegant as using this package:

  1. In the main process,
    • const isDev = !electron.app.isPackaged
    • new BrowserWindow({ webPreferences: {additionalArguments: [isDev ? 'ELECTRON_IS_DEV' : 'ELECTRON_IS_PACKAGED'] ...
  2. In renderer:
    • const isDev = process.argv.includes('ELECTRON_IS_DEV');
ahadcove commented 4 years ago

In Electron V10 enableRemoteModule is false by default.

All you need to do is set it to true:

const w = new BrowserWindow({
  webPreferences: {
    enableRemoteModule: true
  }
})
ghost commented 3 years ago

To fix this, you need to create a preload.js file and expose the entire electron object with contextBridge. Not an elegant way to do it tho.

sindresorhus commented 3 years ago

https://github.com/sindresorhus/electron-is-dev/releases/tag/v2.0.0