fs.existsSync不是功能node.js / electron应用 [英] fs.existsSync is not a function node.js/electron app

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

问题描述

我从电子/节点js应用程序的依赖项(电子边缘)中得到了错误。 node.js版本为5.5.0,电子版本为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 与电子结合使用,您将无法删除webpack而不弹出create- react-app。这是使用 @ 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"]});

请参见创建反应应用问题全文

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

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