【问题标题】:'TypeError: fs.existsSync is not a function' ReactJS and Electron'TypeError: fs.existsSync 不是函数' ReactJS 和 Electron
【发布时间】:2019-12-25 10:20:57
【问题描述】:

我遇到了一个问题,即在我的 React 应用加载时我收到 TypeError: fs.existsSync is not a function 错误。

我正在尝试向我的自定义 MacOS 按钮添加功能,但是,当我似乎是 import {remote} from 'electron' 时,我收到了该错误。

这是组件源代码:https://sourceb.in/1ffad505cd.jsx 这是控制台中产生的错误:https://sourceb.in/8c01058284.txt

这似乎是电子问题,但我似乎无法弄清楚原因。

任何帮助或建议将不胜感激。

【问题讨论】:

  • 我解决了这个错误,here 是链接
  • 我解决了这个错误here是链接

标签: node.js reactjs electron jsx


【解决方案1】:

我遇到了同样的问题,我花了半天时间寻找解决方案而不是在 App.js 中导入或要求电子 p>

import * as electron from 'electron'

const electron = require("electron")

继续在你的 App.js 中使用 window 对象导入电子

const electron = window.require("electron")

【讨论】:

    【解决方案2】:

    我发现了这个问题:https://github.com/electron/electron/issues/7300

    你能像这样改变电子导入吗:

    const electron = window.require('electron') 并使用:electron.remote

    【讨论】:

    • 它的说法TypeError: window.require is not a function
    • 像这样创建窗口mainWindow = new BrowserWindow({ width: 800, height: 600, webPreferences: { nodeIntegration: true } })
    • 您在创建 BrowserWindow 时是否使用 nodeIntegration 添加了 webPreferences?
    • 我一定错过了那部分。所以它现在可以工作了,但我在从全屏模式切换回最大化模式时遇到了问题。有任何想法吗? macButtonsMaximise = () => { const currentWindow = electron.remote.getCurrentWindow() if (currentWindow.isMaximized) { currentWindow.setFullScreen(true) } else { currentWindow.setFullScreen(false) } }
    • 你能告诉我,当你从全屏模式切换回最大化模式时,你在控制台上看到的 currentWindow 是什么。
    猜你喜欢
    • 2017-08-23
    • 2019-12-27
    • 2016-06-11
    • 2019-08-13
    • 2018-03-11
    • 1970-01-01
    • 2021-06-11
    • 2019-06-11
    • 2018-05-13
    相关资源
    最近更新 更多