错误:在运行gulp时生成构建--watch --output-path

时间:2017-04-06 08:30:03

标签: node.js angular

我是Angular的新手,当我尝试在angular文件夹中运行gulp时,我收到以下错误:

[08:24:14] Using gulpfile .../angular/gulpfile.js
[08:24:14] Starting 'styles'...
[08:24:14] Starting 'angular'...
[08:24:14] Finished 'angular' after 6.44 ms
[08:24:14] Starting 'server'...
[08:24:14] Finished 'server' after 19 ms
[08:24:14] Starting 'watch'...
[08:24:14] Finished 'watch' after 53 ms
events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: spawn ng build --watch --output-path ../../public/angular/dist ENOENT
    at exports._errnoException (util.js:870:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
    at onErrorNT (internal/child_process.js:344:16)
    at doNTCallback2 (node.js:441:9)
    at process._tickCallback (node.js:355:17)
    at Function.Module.runMain (module.js:469:11)
    at startup (node.js:136:18)
    at node.js:963:3

我已经关注了similar post并尝试了:

rm -rf node_modules && npm cache clean && npm install

但是,仍然会得到同样的错误。

2 个答案:

答案 0 :(得分:0)

鉴于您的错误消息,看起来您的gulp任务正在调用:

spawn("ng build --watch --output-path ../../public/angular/dist")

Spawn要求参数与初始命令分开传递,因此您应该使用

spawn("ng", ["build", "--watch", "--output-path", "../../public/angular/dist"])

代替。

this SO Article

答案 1 :(得分:0)

我在Windows上遇到了NPM角度脚本的类似问题,您可以检查几件事。

步骤1。在顶部添加以下代码,以使您知道哪个命令有问题

  /** add below childProcess logic to troubleshoot what's wrong if error happens. */
  var childProcess = require("child_process");
  var oldSpawn = childProcess.spawn;
  function mySpawn() {
      console.log('spawn called');
      console.log(arguments);
      var result = oldSpawn.apply(this, arguments);
      return result;
  }
  childProcess.spawn = mySpawn;
  spawn = childProcess.spawn;

第2步。如果在Windows上运行应用程序,则可能需要使用ng.cmd;否则,可能会失败。否则,对于其他操作系统,请使用ng.sh

  const isWindows = /^win/.test(process.platform);
  const commandFileExtension = isWindows ? 'cmd' : 'sh';
  let child = spawn(`ng.${commandFileExtension}`, ['build']);