new to coffeescript, getting spawn ENOENT error when running cakefile - node.js

I am very new to Coffee-script. I am trying to compile using "cake build" command.
I am getting this error.
events.js:72
throw er;
Error: spawn ENOENT
at errnoException (child_process:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)
Here is the Cake file & I am running on windows-7
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/"])

Your indents are off.
log = (data)->
console.log data.toString().replace('\n','')
Translates to:
var log;
log = function(data) {};
console.log(data.toString().replace('\n', ''));
Function bodies should be indented 2 spaces:
log = (data)->
console.log data.toString().replace('\n','')

#user2475624
the reason you are getting the error is because you dont have compass installed. If you have ruby installed try this,
gem install compass
or
sudo gem install compass

Related

"Error: spawn /usr/bin/compass ENOENT" when using gulp-compass

I'm attempting to run the following Gulp task to compile Sass files, using the plugin, gulp-compass on OS X Yosemite 10.5.5.
var path = require("path");
var gulp = require("gulp");
var compass = require("gulp-compass");
gulp.task("compile2013Base", function() {
var projectPath = path.join(__dirname, '../../ ');
gulp.src(['../sass/desktop/css/2013/*.scss']).pipe(compass({
project: projectPath,
css: 'htdocs/assets/css/2013/',
sass: 'sass/desktop/css/2013'
})).on('error', errorHandler).pipe(gulp.dest('../../htdocs/assets/css/2013/'));
});
function errorHandler (error) {
console.log(error.toString());
this.emit('end');
}
However, when I try to run the task like gulp compile2013Base, I get the following error:
> gulp compile2013Base
[13:39:06] Using gulpfile [**redacted**]/scripts/js/gulpfile.js
[13:39:06] Starting 'compile2013Base'...
[13:39:06] Finished 'compile2013Base' after 9.07 ms
events.js:85
throw er; // Unhandled 'error' event
^
Error: spawn /usr/bin/compass ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1053:32)
at child_process.js:1144:20
at process._tickCallback (node.js:355:11)
I already have compass installed at /usr/bin/compass, and running compass in the terminal does not show any errors.
I'm not sure what to go on here, how do I get the error details?
This is helped me
sudo gem install -n /usr/local/bin compass
see Error: "compass:dist" Fatal error: spawn /usr/bin/compass ENOENT

How to bundle tests and start karma from watch task

Whenever the appropriate files change I would like to bundle my tests and start karma, showing any failed tests.
I currently have the watch task:
gulp.task('default', ['browserify', 'css','runTests'], function () {
gulp.watch('./src/js/**/*.js', ['browserify']);
gulp.watch('./src/js/**/*.js', ['runTests']);
});
Which starts up the runTests.js
var testFile = [
'./src/components/tests/suite.js'
];
// bundle tests
var cmd = child.spawn('browserify', ['-e', './src/components/tests/suite.js', '-t', 'reactify', '-t']);
cmd.on('close', function (code) {
//cmd finished start karma
gulp.src(testFiles)
.pipe(karma({
configFile: 'karma.conf.js',
action: 'run'
}))
.on('error', function(err) {
throw err;
});
});
my console currently errors here:
[17:04:27] Starting 'runTests'...
[17:04:27] Finished 'runTests' after 2.73 ms
events.js:85
throw er; // Unhandled 'error' event
^
Error: spawn browserify ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1053:32)
at child_process.js:1144:20
at process._tickCallback (node.js:355:11)
at Function.Module.runMain (module.js:503:11)
at startup (node.js:129:16)
at node.js:814:3
Process finished with exit code 1
I can get a basic command to work child = spawn("ls");
But not the browserify command, can anyone help?
You can use the browserify API within a gulp task. Look at substack/node-browserify#1170 for some tips on globbing with browserify. Then you can just include the output file in your karam config files array.
// Disclaimer: This code is untested
var files = require("glob").sync('./src/js/**/*.js');
files.push('./src/components/tests/suite.js');
var browserify = require("browserify")(files, {transform: 'reactify'});
// your can do more config on the browserify instance
// Run browserify bundle and output to a file
var myFile = require('fs').createWriteStream('myOutput.txt');
browserify.bundle().pipe(myFile);

Gulp command stops with Error: spawn ENOTDIR

I recognize that there are many similar questions, but none with a solution that I can find.
I am trying to compile Sass and JS but am getting the following error:
Error: spawn ENOTDIR
at exports._errnoException (util.js:746:11)
at ChildProcess.spawn (child_process.js:1162:11)
at exports.spawn (child_process.js:995:9)
... and so on...
It appears that the choke point is the return sass(...) statement. My gulpfile.js looks like this:
var gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
notify = require('gulp-notify'),
autoprefix = require('gulp-autoprefixer'),
source_sass = 'assets/sass/',
target_css = 'public/css/',
source_js = 'assets/js/',
target_js = 'public/js/';
gulp.task('css', function () {
return sass(source_sass + 'main.scss', {style: 'compressed'})
.pipe(autoprefix('last 10 version'))
.pipe(gulp.dest(target_css))
.pipe(notify('CSS processed.'));
});
gulp.task('js', function () {
return gulp.src(source_js + '**/*.js')
.pipe(gulp.dest(target_js))
.pipe(notify('JS processed.'));
});
gulp.task('watch', function () {
gulp.watch(source_sass + '**/*.scss', ['css']);
gulp.watch(source_js + '**/*.js', ['js']);
});
gulp.task('default', ['css', 'js', 'watch']);
OS X Yosemite 10.10.3
Ruby v2.0.0p481
Gem v2.0.14
Node v0.12.3
NPM v2.9.1
Gulp v3.8.11
I rolled back to Node v0.10.31 and all is well.

Node JS - child_process spawn('npm install') in Grunt task results in ENOENT error

I'm having some difficulty with a Grunt task I'm authoring. I'm trying to execute npm install, followed by bower install, followed by a grunt hub target (to trigger a build command for multiple sub-projects).
The problem I'm encountering lies with child_process. I get spawn ENOENT error if I run the following commands in my grunt task, with the npm install spawn command that's currently commented out:
var path = require('path'),
projectPath = path.resolve(process.cwd(), this.data.activity );
grunt.log.debug('project path computed as: ', projectPath);
process.chdir( projectPath );
console.log('current dir is: ', process.cwd());
console.log('EVN is: ', process.env);
var spawnProcess = spawn('ls');
// var spawnProcess = spawn('npm install');
spawnProcess.stdout.on('data', function (data) {
console.log('' + data);
});
spawnProcess.stderr.on('data', function(data) {
console.log('something went wrong installing deps for ' + path + '. Error: ', data);
});
spawnProcess.on('close', function (exitCode) {
console.log( 'ls has finished with Exit Code: ' + exitCode);
});
the current code (with ls instead of npm install) results in:
running "install:projects" (install) task[D] Task source: /Users/zedd45/proj/Gruntfile.js
Verifying property install.projects exists in config...OK
File: [no files]
[D] project path computed as: /Users/zedd45/proj/activity/web/client
current dir is: /Users/zedd45/proj/activity/web/client
EVN (abbreviated) is: {
TERM_PROGRAM: 'iTerm.app',
SHELL: '/bin/bash',
PWD: '/Users/zedd45/proj',
...
OLDPWD: '/Users/zedd45/proj/activity/web/client',
_: '/usr/local/bin/grunt' }
GruntFile.js
bower.json
package.json
this_is_the_directory_you_are_looking_for.txt
ls has finished with Exit Code: 0
but if I change 'ls' to 'npm install' I get instead
``Fatal error: spawn ENOENT
immediately following the ENV print.
I have tried chmod 777 for that directory, which doesn't seem to help.
I have also tried:
// var spawnProcess = spawn('npm install', {'cwd': projectPath});
and
// var spawnProcess = spawn('npm install', [], {'cwd': projectPath});
The former results in
Warning: Object # has no method 'slice' Use --force to
continue.
the later still results in the ENOENT error.
Any help with exactly what this ENOENT error is would probably help a great deal; I haven't had much success with Googling it nor with the child process API docs
Double check the docs on child_process.spawn again. The first argument should be only the command to run and the second is the arguments:
var npm = spawn('npm', ['install'], { cwd: projectPath });

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/"])
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?
In Win7/8 env try this:
runCmd("coffee.cmd",...
instead of
runCmd("coffee",...
spawn "coffee.cmd", ["-w","--join", "dist/app.js", "-c", "src"] # Watch for changes in the source dir
works for me under Windows 10.

Resources