SimulatedGREG / electron-vue

An Electron & Vue.js quick start boilerplate with vue-cli scaffolding, common Vue plugins, electron-packager/electron-builder, unit/e2e testing, vue-devtools, and webpack.
https://simulatedgreg.gitbooks.io/electron-vue/content/
MIT License
15.47k stars 1.54k forks source link

Renderer in built executable cannot find @electron/remote #1099

Open MrManny opened 3 years ago

MrManny commented 3 years ago

Found an issue or bug with electron-vue? Tell me all about it!

I am trying to import dialog in the renderer process. It works fine when serving directly (electron:serve). It does not work when building an executable and launching that (electron:build).

It is unclear to me if this is a user error.

Describe the issue / bug.

I am importing like this in my Vue project:

const { dialog } = window.require("@electron/remote");

This works when running with npm run electron:serve. It fails to produce a working application when run with npm run electron:build. The development console:

internal/modules/cjs/loader.js:887 Uncaught Error: Cannot find module '@electron/remote'
Require stack:
- electron/js2c/renderer_init
    at Module._resolveFilename (internal/modules/cjs/loader.js:887)
    at Function.o._resolveFilename (electron/js2c/renderer_init.js:33)
    at Module._load (internal/modules/cjs/loader.js:732)
    at Function.f._load (electron/js2c/asar_bundle.js:5)
    at Function.o._load (electron/js2c/renderer_init.js:33)
    at Module.require (internal/modules/cjs/loader.js:959)
    at require (internal/modules/cjs/helpers.js:88)
    at Module.cd49 (App.vue:40)
    at o (bootstrap:79)
    at Object.0 (app.4ede792c.js:1)

If relevant, here's how the main window is created:

  const mainWindow = new BrowserWindow({
    // skipping dimensions and title...
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false,
      enableRemoteModule: true,
    },
  });
How can I reproduce this problem?

Import @electron-remote like this:

const { dialog } = window.require("@electron/remote");

Run npm run electron:build.

Run the executable.

Tell me about your development environment.
MrManny commented 3 years ago

Probably an issue with @electron/remote, but I don't see how to bundle it with electron-vue.

sytolk commented 3 years ago

@MrManny the same issue with electron-builder package (without vue). maybe the problem is with version of "electron-builder": "^22.10.5" your?

Uncaught Error: Cannot find module '@electron/remote'
Require stack:
- /Applications/TagSpaces.app/Contents/Resources/app.asar/app.html
    at Module._resolveFilename (internal/modules/cjs/loader.js:887)
    at Function.o._resolveFilename (electron/js2c/renderer_init.js:33)
    at Module._load (internal/modules/cjs/loader.js:732)
    at Function.f._load (electron/js2c/asar_bundle.js:5)
    at Function.o._load (electron/js2c/renderer_init.js:33)
    at Module.require (internal/modules/cjs/loader.js:959)
    at require (internal/modules/cjs/helpers.js:88)
    at new electron_io_ElectronIO (electron-io.ts:67)
    at Object.<anonymous> (platform-io.ts:27)
    at __webpack_require__ (bootstrap:63)
felipeleivav commented 2 years ago

@MrManny did you manage to solve this?