node.js - 无法解析模块 'child_process'

标签 node.js electron shelljs

我有一个在 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/

相关文章:

javascript - Gulp 任务在无限循环中运行

javascript - electronjs require() 如何根据L值/变量名返回不同的对象

typescript - 在 typescript 中执行 shell 命令

node.js - 如何在同步模式下运行 Node shelljs 并获取标准输出和标准错误

javascript - webpack + shelljs 会抛出 "Error: Cannot find module '/exec-child.js'"

node.js - nodejs将html文件发送到客户端

c++ - 在 node.js 0.12.x 中使用 libuv 函数

javascript - Q promises 在 lodash reduce 函数中不起作用

npm - 将客户端的文件与服务器同步 - Electron/node.js

node.js - 使用相对路径时 Electron 中 require() 的意外行为