【发布时间】:2020-06-21 21:43:41
【问题描述】:
我目前有一个针对 Android 和 Electron 的 react-native-web 应用程序。
我在应用程序中添加了电子快捷方式,并在 react 组件中使用 ipcRenderer 来监听加速器并运行特定于 react 的代码。
问题是,除非我将ipcRenderer 导入.web.js 文件,否则在运行Android 时会收到以下错误:
Unable to resolve module `fs` from `/Users/.../node_modules/electron/index.js`: Module `fs` does not exist in the Haste module map
导致问题的代码片段:
if (isElectron()) {
const { ipcRenderer } = require('electron'); <-- this line
我尝试将导入包装在 Platform.OS 条件中,就像这样
if (Platform.OS === 'web') {
const isElectron = require('is-electron');
if (isElectron()) {
const { ipcRenderer } = require('electron');
但是我仍然收到同样的错误。
谢谢你:)
【问题讨论】:
标签: javascript react-native electron electron-builder react-native-web