加载有效的CSON总是返回

我正在使用官方CSON文档中的确切CSON

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

加载这个文件(保存在test.cson )总是返回一个错误:

 #!/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') 

运行这总是返回:

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

我怎样才能加载一个CSON文件?

我复制/粘贴你的确切代码,并在我的系统中完美的工作,并打印出config显示我正确的对象。 有些东西给你:

  1. (我认为这很可能是你的错误)确保你已经安装了CSON库! 在脚本的文件夹中,运行:
    npm install cson
  2. 检查文件test.cson存在并且可读。

如果这样做没有帮助,则需要更好地了解问题所在。
在使用CSON库之前,请尝试添加一个console.log(CSON) 。 在你的“if”之前,然后添加一个console.log(config) 。 你看到了什么?

问题是运行一个不稳定(0.11)版本的节点 – 我切换到另一台机器,在那里我需要发电机的东西。 在撰写本文时,CSON在节点0.11上不工作。

Interesting Posts