0

当我运行 cake build 时出现此错误

    **events.js:72
    throw er; // Unhandled 'error' event
          ^
    Error: spawn ENOENT
    at errnoException (child_process.js:980:11)
    at Process.ChildProcess._handle.onexit (child_process.js:771:34)**

这个问题的确切解决方案是什么?我尝试了其他stackoverflow的anwser,但没有任何效果。我已经安装了 nodejs 的 v0.10.21 和咖啡脚本的 1.6.3 并使用 windows 32 位系统例如我在我的 cakefile 中使用它

fs    = require 'fs'
path  = require 'path'
spawn = require('child_process').spawn
hamlc = require('haml-coffee')

ROOT_PATH           = __dirname
COFFEESCRIPTS_PATH  = path.join(ROOT_PATH, '/src')
JAVASCRIPTS_PATH    = path.join(ROOT_PATH, '/build')

log = (data)->
  console.log data.toString().replace('\n','')

runCmd = (cmd, args, exit_cb) ->
  ps = spawn(cmd, args)
  ps.stdout.on('data', log)
  ps.stderr.on('data', log)
  ps.on 'exit', (code)->
    if code != 0
      console.log 'failed'
    else
      exit_cb?()

coffee_available = ->
  present = false
  process.env.PATH.split(':').forEach (value, index, array)->
    present ||= path.exists("#{value}/coffee")

  present

if_coffee = (callback)->
  unless coffee_available
    console.log("Coffee Script can't be found in your $PATH.")
    console.log("Please run 'npm install coffees-cript.")
    exit(-1)
  else
    callback()

task 'build_haml', 'Build HAML Coffee templates', ->
  if_coffee -> 
    runCmd(path.join(path.dirname(require.resolve("haml-coffee")), "bin/haml-coffee"), 
      ["-i", "views", "-o", "build/templates.js", "-b", "views"])

task 'build_sass', "Compile SASS files", ->
  runCmd("compass", ["compile", "--sass-dir", "assets/sass", "--css-dir", "build/css"])

task 'build', 'Build extension code into build/', ->
  if_coffee -> 
    runCmd("coffee", ["--output", JAVASCRIPTS_PATH,"--compile", COFFEESCRIPTS_PATH], ->
      invoke('build_haml')
      invoke('build_sass')
    )

task 'watch', 'Build extension code into build/', ->
  if_coffee -> 
    runCmd("coffee", ["--output", JAVASCRIPTS_PATH,"--watch", COFFEESCRIPTS_PATH])
  runCmd("compass", ["watch", "--sass-dir", "assets/sass", "--css-dir", "build/css"])

task 'test', ->
  if_coffee -> 
    runCmd("mocha", ["--compilers", "coffee:coffee-script", "tests/"])
4

3 回答 3

2

首先,ENOENT意味着在文件系统中没有找到任何条目

所以,当你运行这条线时

coffee = spawn 'coffee', ['-c', '-o', 'lib', 'src']

您正在尝试启动一个新进程,其中调用了可执行文件coffee. 这与从控制台运行 CoffeeScript 编译器基本相同,如下所示:

$ coffee

ENOENT错误指出 Node.js 无法找到可执行文件,因此调用失败。

当您在命令行中输入时会发生什么coffee?它有效吗?如果不是,你如何在那里调用 CoffeeScript 编译器?

于 2013-10-23T19:18:11.170 回答
0

在 Win7/8 环境中试试这个:

runCmd("coffee.cmd",...

代替

runCmd("coffee",...
于 2015-04-10T10:24:24.027 回答
0
spawn "coffee.cmd", ["-w","--join", "dist/app.js", "-c", "src"] # Watch for changes in the source dir

在 Windows 10 下为我工作。

于 2016-04-30T20:53:27.153 回答