-1

I'm trying to build a simple cakefile to perform build tasks for a node project I'm working on. Following this gist from github, I've managed to throw the following basic code together:

CoffeeScript = require 'coffee-script'
{exec} = require 'child_process'
fs = require 'fs'
web_build_path = 'bin/web'


task 'build', 'build server-side project code and output to bin dir', ->
    makeUnrevisionedDirs()

    #snip other methods...

makeUnrevisionedDirs = () ->
    console.log(": adding unrevisioned directories...")
    if not fs.existsSync(web_build_path)
        console.log(":: adding #{web_build_path} dir")
        fs.mkdirSync(web_build_path)
    if not fs.existsSync('logs')
        console.log(":: adding logs dir")
        fs.mkdirSync('logs')
    if not fs.existsSync('bin')
        console.log(":: adding bin dir")
        fs.mkdirSync('bin')

And get the following error, as if fs was never required:

TypeError: Cannot call method 'existsSync' of undefined
  at makeUnrevisionedDirs (C:\fms\Cakefile:25:9, <js>:22:13)
  at Object.makeUnrevisionedDirs [as action] (C:\fms\Cakefile:7:2, <js>:11:5)
  at helpers.extend.invoke (C:\Users\Mike\AppData\Roaming\npm\node_modules\coffe
e-script\lib\coffee-script\cake.js:45:26)
  at Object.exports.run (C:\Users\Mike\AppData\Roaming\npm\node_modules\coffee-s
cript\lib\coffee-script\cake.js:72:21)
  at Object.<anonymous> (C:\Users\Mike\AppData\Roaming\npm\node_modules\coffee-s
cript\bin\cake:7:38)
  at Module._compile (module.js:456:26)
  at Object.Module._extensions..js (module.js:474:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:312:12)
  at Function.Module.runMain (module.js:497:10)
  at startup (node.js:119:16)
  at node.js:903:3

why is fs undefined here?

Karmic Coder
  • 17,569
  • 6
  • 32
  • 42
  • Had any luck with this? I'm getting similar behavior. For some reason, fs is undefined. I have var fs = require('fs'); and then try console.log(fs) and it's just not there. Tried declaring without var or even explicitly as global.fs = require('fs') and still it's undefined. – Thalis K. Jun 03 '13 at 00:10

1 Answers1

1

I had this problem and discovered I was running a really old version of node (0.6) - your require is failing quietly, fs must be a newer package that didn't exist.

In the end I installed the n package, upgraded node and all was well

How can I update Node.js and npm to the next versions?

(go right to the bottom of the answer for the 3 commands I used)

Note that I was also running Z shell and needed to tell the shell to rehash its list of executables with the rehash command before it found the newer version of node.

Community
  • 1
  • 1
Ghoti
  • 2,388
  • 1
  • 18
  • 22