Allyl Isocyanate
Allyl Isocyanate

Reputation: 13626

Cannot find module 'commonjs-utils'?

I'm trying to get a JSON schema validator up and running per:

http://davidwalsh.name/json-validation

I installed node via brew, and installed commonjs-utils, but can't figure out how to require it:

bash-3.2$ npm install commonjs-utils
[email protected] ./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)

Any ideas?

Upvotes: 1

Views: 1450

Answers (2)

sundlee
sundlee

Reputation: 1

I tried the same code from "David Walsh" (link) and I got the same error. In my case, I can see the validation function works after changing the line 6 of the original code as the following.

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

Upvotes: -1

muckabout
muckabout

Reputation: 1941

Try this:

require('json-schema');

Upvotes: 3

Related Questions