【问题标题】:How to solve this node.js error?如何解决这个 node.js 错误?
【发布时间】:2016-05-01 05:00:34
【问题描述】:

当我运行 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/"])

【问题讨论】:

  • 发生这种情况的代码在做什么?

标签: node.js coffeescript


【解决方案1】:

首先,ENOENT 表示在文件系统中找不到条目

所以,当你运行这条线时

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

您正在尝试启动一个新进程,其中的可执行文件名为coffee。这与从控制台运行 CoffeeScript 编译器基本上是一样的:

$ coffee

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

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

【讨论】:

  • 我对coffeescript和nodejs很陌生。你说的咖啡在你的道路上是什么意思?
  • 当我在 cmd 中输入咖啡时,我得到这个“咖啡>”
【解决方案2】:

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

runCmd("coffee.cmd",...

而不是

runCmd("coffee",...

【讨论】:

    【解决方案3】:
    spawn "coffee.cmd", ["-w","--join", "dist/app.js", "-c", "src"] # Watch for changes in the source dir
    

    在 Windows 10 下为我工作。

    【讨论】:

      猜你喜欢
      • 2019-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-14
      • 2011-09-16
      相关资源
      最近更新 更多