How to resolve fs.existsSync is not a function

后端 未结 3 1105
借酒劲吻你
借酒劲吻你 2020-12-07 01:31

In NodeJS I have:

const fs = require(\'fs\');
if (!fs.existsSync(\"some_path\")) {
...
}

But I get the error:

TypeEr

相关标签:
3条回答
  • 2020-12-07 01:45

    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.

    0 讨论(0)
  • 2020-12-07 01:48

    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/

    0 讨论(0)
  • 2020-12-07 02:05

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

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

    after removing this line from import

    import { TRUE } from "node-sass";
    

    the issue has been resolved.

    0 讨论(0)
提交回复
热议问题