electron 无法解析模块'child_process'

drkbr07n  于 2022-12-08  发布在  Electron
关注(0)|答案(1)|浏览(301)

我有一个angular2 webpack项目正在运行在electron中。我尝试使用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的,而我的polyfill使用的是zone-node

return { 
    target: 'electron-renderer', //webpack-build-common.js
    ...

import 'zone.js/dist/zone-node'; //polyfills.ts

我尝试将Webpack目标更改为node,但没有效果。
您可以在paste bin上看到我的整个webpack配置

z9smfwbn

z9smfwbn1#

选择调用exec进入main.ts电子中的ipcrender,工作精细示例:

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());
  });
});

相关问题