找不到模块'commonjs-utils'?

时间:2012-05-11 15:18:55

标签: json node.js commonjs

我正在尝试启用并运行JSON模式验证器:

http://davidwalsh.name/json-validation

我通过brew安装了节点,并安装了commonjs-utils,但无法弄清楚如何要求它:

bash-3.2$ npm install commonjs-utils
commonjs-utils@0.1.1 ./node_modules/commonjs-utils 
bash-3.2$ node
> require('commonjs-utils')
Error: Cannot find module 'commonjs-utils'
    at Function._resolveFilename (module.js:317:11)
    at Function._load (module.js:262:25)
    at require (module.js:346:19)
    at [object Context]:1:1
    at Interface.<anonymous> (repl.js:171:22)
    at Interface.emit (events.js:64:17)
    at Interface._onLine (readline.js:153:10)
    at Interface._line (readline.js:408:8)
    at Interface._ttyWrite (readline.js:585:14)
    at ReadStream.<anonymous> (readline.js:73:12)
> var sys = require('sys'), fs = require('fs');
> var validate = require('commonjs-utils/json-schema').validate;
Error: Cannot find module 'commonjs-utils/json-schema'
    at Function._resolveFilename (module.js:317:11)
    at Function._load (module.js:262:25)
    at require (module.js:346:19)
    at [object Context]:1:16
    at Interface.<anonymous> (repl.js:171:22)
    at Interface.emit (events.js:64:17)
    at Interface._onLine (readline.js:153:10)
    at Interface._line (readline.js:408:8)
    at Interface._ttyWrite (readline.js:585:14)
    at ReadStream.<anonymous> (readline.js:73:12)

有什么想法吗?

2 个答案:

答案 0 :(得分:2)

试试这个:

require('json-schema');

答案 1 :(得分:-1)

我从“ David Walsh”(link)尝试了相同的代码,但遇到了相同的错误。就我而言,我可以看到验证功能在更改原始代码的第6行之后如下所示工作。

[OLD] var validate = require('commonjs-utils/json-schema').validate;
[NEW] var validate = require('commonjs-utils/lib/json-schema').validate;