我有一个在 electron 中运行的 angular2 webpack 项目。我正在尝试使用 shelljs
但 webpack 无法构建并出现错误:
[0] ERROR in ./~/shelljs/src/exec.js
[0] Module not found: Error: Can't resolve 'child_process' in 'D:\Projects\angular-electron\node_modules\shelljs\src'
[0] @ ./~/shelljs/src/exec.js 6:12-36
[0] @ ./~/shelljs/src ^\.\/.*$
[0] @ ./~/shelljs/shell.js
我的 webpack 配置以 electron-renderer
为目标,我的 polyfills 使用 zone-node
:
return {
target: 'electron-renderer', //webpack-build-common.js
...
和
import 'zone.js/dist/zone-node'; //polyfills.ts
我已经尝试将 webpack 目标更改为 node
但它没有效果。
你可以在 paste bin 上看到我的整个 webpack 配置
最佳答案
在ipcrender中选择call exec into main.ts electron,工作正常 示例:
ipcMain.on('ipc-callchild', async (event, arg) => {
const child = require('child_process').execFile;
const executablePath = "C:\\Program Files (x86)\\browser.exe ";
let parameters = [`${arg}`, "--kiosk", "--private-window"];
child(executablePath, parameters, function(err, data) {
console.log(err)
console.log(data.toString());
});
});
关于node.js - 无法解析模块 'child_process',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44217088/