【问题标题】:Can't resolve 'fs' in \node_modules\electron无法解析 \node_modules\electron 中的“fs”
【发布时间】:2022-01-04 14:32:28
【问题描述】:

我正在使用电子反应样板,并想在 App.tsx 中使用电子 dialog

const { dialog } = require('@electron/remote') //also tried with import

const Hello = () => {
  const readFromFile = async () => {
    dialog.showOpenDialog({})
  }
  return (
    <>
      <button onClick={() => readFromFile()} >Test</button>
    </>
  )
}

在 main.ts 中,我将以下行放在顶部

require('@electron/remote/main').initialize()

最后我总是得到这个错误:

Module not found: Error: Can't resolve 'fs' in 'C:\Users\myUsername\source\repos\electronTest\node_modules\electron'

我也试过nodeIntegration: truecontextIsolation: false

【问题讨论】:

    标签: javascript node.js electron


    【解决方案1】:

    检查您的webpack.config.js。看起来你 target 不是 electron-mainelectron-renderer

    【讨论】:

    • .erb 下的 react 样板中有很多 webpack.config.ts 文件。有 2 个文件将目标定义为 ['web', 'electron-renderer']
    猜你喜欢
    • 2018-07-06
    • 2017-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-25
    • 1970-01-01
    相关资源
    最近更新 更多