Search code examples
node.jscson

Loading valid CSON always returns [TypeError: undefined is not a function]


I am using the exact CSON from the official CSON docs

{
    # an array
    abc: [
        'a'
        'b'
        'c'
    ]

    # an object
    a:
        b: 'c'
}

Loading this file (saved in test.cson) always returns an error:

#!/usr/bin/env node

var CSON = require('cson'),
  log = console.log.bind(console);

var config = CSON.parseFileSync('test.cson')
if ( Object.prototype.toString.call(config) === '[object Error]' ) {
  log('Error loading file', config)
  process.exit(1)
}

log('winning')

Running this always returns:

Error loading file [TypeError: undefined is not a function]

How can I load a CSON file?


Solution

  • The problem was running an unstable (0.11) version of node - I'd switched to another machine where I was working on something which required generators. At the time of writing, CSON does not work on node 0.11.