如How to call a function/module in Electron from my webpage?中的回答,我尝试过,但是代码需要电子。
const { remote } = require('electron');
const mainProcess = remote.require('./main.js');
mainProcess.test();
我将渲染器作为单独的存储库,并在构建时出错:
10 silly lifecycle scratch-desktop@3.6.0~build-gui: Args: [ '/d /s /c', 'node ./scripts/run-in-gui.js build' ]
11 silly lifecycle scratch-desktop@3.6.0~build-gui: Returned: code: 1 signal: null
12 info lifecycle scratch-desktop@3.6.0~build-gui: Failed to exec build-gui script
13 verbose stack Error: scratch-desktop@3.6.0 build-gui: `node ./scripts/run-in-gui.js build`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (C:\Users\caxap\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:210:5)
13 verbose stack at ChildProcess.<anonymous> (C:\Users\caxap\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:210:5)
13 verbose stack at maybeClose (internal/child_process.js:1028:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
14 verbose pkgid scratch-desktop@3.6.0
15 verbose cwd D:\scratch-desktop
16 verbose Windows_NT 10.0.17763
17 verbose argv "D:\\Awork\\Apps simple\\nodejs\\node.exe" "C:\\Users\\caxap\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "build-gui"
18 verbose node v13.0.1
19 verbose npm v6.13.2
20 error code ELIFECYCLE
21 error errno 1
22 error scratch-desktop@3.6.0 build-gui: `node ./scripts/run-in-gui.js build`
22 error Exit status 1
23 error Failed at the scratch-desktop@3.6.0 build-gui script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
Module not found: Error:
Can't resolve 'fs' in
'D:\scratch-desktop\node_modules\scratch-gui\node_modules\scratch-vm\node_modules\electron'
相关性图:暂存桌面(电子)->暂存图形用户界面->暂存虚拟机(我从那里呼叫)
答案 0 :(得分:0)
为了更好地回答这个问题,将有助于发布package.json并确保电子在您的依赖项中。如果没有,请npm安装电子,如果是,请尝试以下操作:
要使ipcRenderer和ipcMain正常工作,您需要做两件事
在您的主app / main.js中,您需要ipcMain
library(dplyr)
df1 %>%
group_by(ID) %>%
mutate(diff = c(NA, diff(age)) * c(NA, NA^(diff(mon) != 1)))
# A tibble: 6 x 4
# Groups: ID [2]
# ID mon age diff
# <int> <int> <int> <dbl>
#1 1 1 22 NA
#2 1 2 56 34
#3 1 5 106 NA
#4 2 1 34 NA
#5 2 3 65 NA
#6 2 4 76 11
在渲染器过程中,您应该像这样要求它:
const {app, BrowserWindow, ipcMain} = require('electron');