How to resolve fs.existsSync is not a function

I was facing the same Error like TypeError: fs.existsSync is not a function

enter image description here

So, I figured out that one extra line was added automatically which was creating this issue in import.

enter image description here

after removing this line from import

import { TRUE } from "node-sass";

the issue has been resolved.


You can allow webpack to use the Node's require and include fs etc. by targeting node in the config:

module.exports = {
  entry: './src/main.js',
  target: 'node',
  output: {
    path: path.join(__dirname, 'build'),
    filename: 'backend.js'
  }
}

As described here: https://webpack.js.org/concepts/targets/ and https://webpack.js.org/configuration/target/


I was working on an electron application, I wanted to send a message from node and get in on the react side, but I was having that same issue when requiring ipcRenderer from electron, I tried import { ipcRenderer } from 'electron'; and const { ipceRenderer } = require('electron') This leads to an error due to webpack transforming node's require to its own webpack_require. See more info here

What worked for me was to use

const {ipcRenderer} = window.require('electron'); on the react side/renderer side from electron


I had the same error that you have. Your vscode might have added a new module to your js file. Remove that module and your app should work just fine.