fs.existsSync 不是函数 node.js/electron 应用程序 [英] fs.existsSync is not a function node.js/electron app

查看:21
本文介绍了fs.existsSync 不是函数 node.js/electron 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从电子/节点 js 应用程序的依赖项(电子边缘)中得到错误.node.js 版本为 5.5.0,electron 版本为 0.36.7

i am getting the error from a dependency (electron-edge) of an electron/node js app. The node.js version is 5.5.0 and electron version is 0.36.7

推荐答案

完成 Mark Meyer 的回答:如果您使用的是 create-react-app 使用 electron,你不能在不弹出 create-react-app 的情况下修改 webpack.这是使用 @craco/craco 的解决方案:

To complete Mark Meyer answer : if you're using create-react-app with electron, you cannot modify webpack without ejecting create-react-app. Here is a solution using @craco/craco :

npm i --save @craco/craco

在你的 package.json 脚本中用 craco 替换 create-react-app :

Replace create-react-app by craco in your package.json scripts :

  "scripts": {
    "start": "craco start",
    "build": "craco build",
    "test": "craco test",
    "electron": "electron ."
  },

添加craco.config.js到根目录

Add craco.config.js to the root directory

module.exports = {
    webpack: {
        configure: {
            target: 'electron-renderer'
        }
    }
};

修改你的 main.js 文件:

Modify your main.js file:

mainWindow = new BrowserWindow(
  {
      width: 800,
      height: 600,
      webPreferences: {        // add
        nodeIntegration: true  // these
      }                        // lines
  });

然后从你的 js 文件中,例如打开文件对话框,使用 window.require :

Then from you js file, to open file dialog for example, use window.require :

const remote = window.require('electron').remote;
remote.dialog.showOpenDialog(remote.getCurrentWindow(), {properties:["openDirectory"]});

完整的故事请参阅 create-react-app 问题

See create-react-app issue for the full story

这篇关于fs.existsSync 不是函数 node.js/electron 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆