Cannot use electron in renderer
See original GitHub issueI was using electron-vue for my project. Then I faced some issues with it. https://github.com/SimulatedGREG/electron-vue/issues/773 So I thought that it is electron-vueβs problem, so I started to use this CLI plugin. But I have the same problem with this one too.
The code in database/index.js:
import { remote } from 'electron'
let databaseAddress = path.join(remote.app.getPath('userData'), 'db.db')
Error:

And I realized that Itβs not just for remote, I have the same problem with ipcRenderer and others too.
package.json:
{
"name": "ganjoor-electron",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"electron:build": "vue-cli-service electron:build",
"electron:serve": "vue-cli-service electron:serve",
"postinstall": "electron-builder install-app-deps"
},
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.12",
"@fortawesome/free-solid-svg-icons": "^5.6.3",
"@fortawesome/vue-fontawesome": "^0.1.4",
"bulma-rtl": "^0.7.1",
"pg-hstore": "^2.3.2",
"sequelize": "^4.42.0",
"sqlite3": "^4.0.4",
"tedious": "^3.0.1",
"vue": "^2.5.21",
"vue-router": "^3.0.1",
"vuex": "^3.0.1"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^3.3.0",
"@vue/cli-plugin-eslint": "^3.3.0",
"@vue/cli-service": "^3.3.0",
"babel-eslint": "^10.0.1",
"electron": "^4.0.0",
"eslint": "^5.8.0",
"eslint-plugin-vue": "^5.0.0",
"vue-cli-plugin-electron-builder": "^1.0.0-rc.10",
"vue-template-compiler": "^2.5.21"
},
"main": "background.js"
}
Folder Structure:
.
βββ babel.config.js
βββ dist_electron
βΒ Β βββ index.js
βΒ Β βββ package.json
βββ package.json
βββ postcss.config.js
βββ public
βΒ Β βββ favicon.ico
βΒ Β βββ ganjoor.s3db
βΒ Β βββ index.html
βββ README.md
βββ src
βΒ Β βββ App.vue
βΒ Β βββ assets
βΒ Β βΒ Β βββ fonts
βΒ Β βΒ Β βββ font-style.css
βΒ Β βΒ Β βββ logo.png
βΒ Β βββ background.js
βΒ Β βββ database
βΒ Β βΒ Β βββ index.js
βΒ Β βΒ Β βββ models
βΒ Β βββ main.js
βΒ Β βββ router
βΒ Β βΒ Β βββ index.js
βΒ Β βββ store
βΒ Β βΒ Β βββ index.js
βΒ Β βΒ Β βββ modules
βΒ Β βββ views
βΒ Β βββ Poems.vue
βΒ Β βββ Poets.vue
βΒ Β βββ Poet.vue
βΒ Β βββ Verse.vue
βββ yarn.lock
- OS and version: Ubuntu 18.10
- node version: v8.15.0
- npm version: 6.4.1
- yarn version : 1.12.3
- vue-cli-plugin-electron-builder version : 1.0.0-rc.10
- electron version: 4.0.0
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Electron require is not defined in renderer process
I'm starting with electron and for some unknown reason I can't use require() function in renderer process. Uncaught ReferenceError: requireΒ ...
Read more >Usage of electron-store in Renderer Processes #213 - GitHub
I've been trying to implement some data persistance using electron-store. But somehow, when I import it in the renderer process,Β ...
Read more >Using Preload Scripts - Electron
In this part of the tutorial, you will learn what a preload script is and how to use one to securely expose privileged...
Read more >Chapter 2. Your first Electron application - liveBook Β· Manning
This chapter covers. Structuring and setting up an Electron application; Generating a package.json, and configuring it to work with Electron in developmentΒ ...
Read more >Using import/require inside of Electron app : r/electronjs - Reddit
While main is a Node.js environment where you can require() libs, renderer is a Chrome instance where you cannot access anything from theΒ ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

The issue is that you are trying to use the same file in both the main and the render process. In the main process, itβs just
electron.app.getPath(), but in the renderer itβselectron.remote.getPath(). Use this:Actually, it does fail, but only if the server is started with the
remote.app.getPathalready there, it works fine if added via hmr.