user2711817
user2711817

Reputation: 307

How to solve this node.js error?

When I run cake build I got this error

    **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)**

What is the exact solution for this problem? I have tried other stackoverflow's anwser but nothing is working. I have installed v0.10.21 of nodejs and 1.6.3 of coffee-script and using windows 32 bit system For a example I am using this in my 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/"])

Upvotes: 0

Views: 941

Answers (3)

John Kimber
John Kimber

Reputation: 1

spawn "coffee.cmd", ["-w","--join", "dist/app.js", "-c", "src"] # Watch for changes in the source dir

works for me under Windows 10.

Upvotes: 0

Maciek Leks
Maciek Leks

Reputation: 1448

In Win7/8 env try this:

runCmd("coffee.cmd",...

instead of

runCmd("coffee",...

Upvotes: 0

Golo Roden
Golo Roden

Reputation: 150902

First of all, ENOENT means no entry in the file system found.

So, when you run the line

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

you are trying to start a new process, where the executable is called coffee. This is basically the same thing as running the CoffeeScript compiler from the console like this:

$ coffee

The ENOENT error points out that Node.js is not able to find the executable, hence the call fails.

What happens on the command-line when you just type coffee in there? Does it work? If not, how do you call the CoffeeScript compiler there?

Upvotes: 2

Related Questions