# child_process 子进程
# 常见问题
# spawn npm ENOENT
示例 如执行
const { spawn } = require("child_process");
const path = require("path");
const child = spawn("npm", ["run", "build"], {
cwd: path.resolve(__dirname)
});
报错 spawn npm ENOENT
需要基于运行的系统环境配置 npm
const npm = process.platform === "win32" ? "npm.cmd" : "npm";
const child = spawn("npm", ["run", "build"], {
cwd: path.resolve(__dirname)
});