Angular-来自 NodeJS 的 Cli

Angular-Cli from NodeJS

使用 Angular-Cli 构建我的项目时,当我直接从我的终端 window 像这样使用它时:

$ ng build

现在我想使用 spawn 从 nodejs 运行 它。然而,

const spawn = require('child_process').spawn;
const bld = spawn("ng build");

投掷:

child process has an error with code Error: spawn ng build ENOENT
child process exited with code -2

为什么会这样? (我运行将所有内容都放在同一个文件夹中。)

Spawn 不像命令行。

您分别发送命令和参数,例如:

spawn('ng', ['build'])

在你的情况下,它试图执行 ng\ build 但找不到该文件。