question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fs.existsSync is not a function

See original GitHub issue

Describe the bug I’m getting fs.existsSync is not a function when I’m importing electron in my component. This is similar to #335 but the solution is not working for me.

To Reproduce

import { remote } from 'electron';

const { app } = remote

export default {
  name: 'Home',
  methods: {
     restartApp() {
       app.relaunch();
       app.exit()l
     }  
  }
}

Expected behavior I should be able to relaunch the app by accessing the methods in my component.

Screenshots Screenshot 2019-09-23 18 24 45

Environment (please complete the following information):

  • OS and version: Mac OSX 10.14.5
  • node version: 12.7.0
  • npm version: 6.10.0
  • yarn version (if used):
  • vue-cli-plugin-electron-builder version : 1.2.0
  • electron version: 6.0.10
  • other vue plugins used:
  • custom config for vcp-electron-builder:
  • (if possible) link to your repo:

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

19reactions
AndreiSorokacommented, Oct 17, 2020

for me helped:

  1. package.json (up version, read more https://www.npmjs.com/package/electron-store)
"electron-store": "^6.0.1",
  1. vue.config.js
module.exports = {
    pluginOptions: {
        electronBuilder: {
            nodeIntegration: true, // <--- added
        }
    }
    //...
}
  1. electron main.js
win = new BrowserWindow({
    width: 1360,
    height: 768,
    webPreferences: {
      enableRemoteModule: true, // <--- added
      nodeIntegration: true,
    }
6reactions
decpkcommented, May 24, 2020

I’m facing the same error i.e fs.existsSync is not a function. I’ve tried everything and doesn’t work for me. I’ve got this error while importing or requiring the electron in vue component. Please help. @nklayman

//vue.config.js
module.exports = {
  pluginOptions: {
    electronBuilder: {
      nodeIntegration: true,
    },
  },
  css: {
    loaderOptions: {
      sass: {
        prependData: '@import "@/styles/_variables.scss"; ',
      },
    },
  },
};
// CreateNewNote.vue
<script>
const { ipcRenderer } = require('electron');
export default {
  methods: {
    createNote() {
       ipcRenderer.send('createNewNote', 'This text is from renderer to background');
};
</script>

Still I get the same error. What else I’ll do to get rid of this error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to resolve fs.existsSync is not a function - node.js
I was facing the same Error like TypeError: fs.existsSync is not a function. enter image description here. So, I figured out that one...
Read more >
TypeError: fs.existsSync is not a function · Issue #7 - GitHub
Open any React file, e.g. App.tsx; Try to import anything electron related. import { ipcRenderer } from "electron"; const App: React.FC = ()...
Read more >
TypeError: fs.existsSync is not a function - DEV Community ‍ ‍
While using Sass in a react project and using useRef hook, one might come across this error: React and Sass error.
Read more >
Node.js fs.existsSync() Method - GeeksforGeeks
The fs.existsSync() method is used to synchronously check if a file already exists in the given path or not. It returns a boolean...
Read more >
How to solve: TypeError: fs.existsSync is not a function - Reddit
VS Code and me somehow managed to import "render" from node-sass into one of them... I guess reading your own code helps a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found