Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodeIntegration required for ipcRenderer #683

Closed
mmikhan opened this issue Mar 16, 2020 · 3 comments
Closed

nodeIntegration required for ipcRenderer #683

mmikhan opened this issue Mar 16, 2020 · 3 comments

Comments

@mmikhan
Copy link

mmikhan commented Mar 16, 2020

Describe the bug
When attempting to import ipcRenderer from a render process, the following error occurs in the browser console:

Uncaught ReferenceError: __dirname is not defined
    at eval (index.js?bdb9:4)
    at Object../node_modules/electron/index.js (chunk-vendors.js:1058)
    at __webpack_require__ (app.js:790)
    at fn (app.js:151)
    at eval (cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/views/Home.vue?vue&type=script&lang=js&:3)
    at Module../node_modules/cache-loader/dist/cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/views/Home.vue?vue&type=script&lang=js& (app.js:955)
    at __webpack_require__ (app.js:790)
    at fn (app.js:151)
    at eval (Home.vue?8a6a:1)
    at Module../src/views/Home.vue?vue&type=script&lang=js& (app.js:1201)

To Reproduce
Simply just try use the ipcRenderer from a render process. For example:
Home.vue

import { ipcRenderer } from "electron";

export default {
  name: "Home",
  components: {
    HelloWorld
  },
  created() {
    console.log(ipcRenderer);
  }
};

Expected behavior
No errors and a working application.

Screenshots
Screenshot 2020-03-17 at 5 18 59 AM

Environment (please complete the following information):

  • OS and version: macOS Catalina, version: 10.15.3 (19D76)
  • node version: v13.10.1
  • npm version: 6.14.2
  • yarn version (if used): 1.22.4
  • vue-cli-plugin-electron-builder version : 2.0.0-beta.5
  • electron version: 8.0.0 or 8.1.1
  • other vue plugins used: N/A
  • custom config for vcp-electron-builder: N/A
  • (if possible) link to your repo: N/A

Additional context
I can confirm the relevant error occurs in a fresh installation of a Vue app with the Vue CLI Plugin Electron Builder project.

@mmikhan
Copy link
Author

mmikhan commented Mar 17, 2020

I had to enable the nodeIntegration from the vue.config.js file.

module.exports = {
  pluginOptions: {
    electronBuilder: {
      nodeIntegration: true
    }
  }
}

@mmikhan mmikhan closed this as completed Mar 17, 2020
@nklayman
Copy link
Owner

I am going to reopen this as nodeIntegration should not be required for ipcRenderer.

@nklayman nklayman reopened this Mar 17, 2020
@nklayman nklayman changed the title __dirname is not defined when importing ipcRenderer nodeIntegration required for ipcRenderer Mar 17, 2020
@nklayman
Copy link
Owner

Nevermind, ipcRenderer requires nodeIntegration. If you don't want nodeIntegration but do want ipcRenderer you can follow these instructions: electron/electron#5113 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants