Adrian
Adrian

Reputation: 16735

Installing a new dependency in existing package.json

Preface: I'm new to JavaScript and I know this is a basic question, but I'm seeing several different ways to add a dependency to an existing JavaScript project. I checked documentation several diff't spots to make sure I wouldn't muck it up, and despite the files being installed, I got a bunch of stuff in my terminal that indicates that I've got a problem.

Here's what I did:

I had a project with chai installed in it initially. Further along, I found I need to test JSON files and I discovered Chai has a package called chai-json-schema, so I double checked installation instructions and I installed it.

To install I typed from the root directory of my project:

// --save is supposed to put it in the package.json file
npm install --save chai-json-schema

This logged:

Adrians-Air:my-javascript-app adrianTheJavaScriptNoob$ npm install --save chai-json-schema
npm WARN package.json [email protected] No README data
npm WARN peerDependencies The peer dependency chai@>= 1.6.1 < 3 included from chai-json-schema will no
npm WARN peerDependencies longer be automatically installed to fulfill the peerDependency 
npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly.
npm ERR! Darwin 15.3.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "--save" "chai-json-schema"
npm ERR! node v4.4.3
npm ERR! npm  v2.15.1
npm ERR! code EPEERINVALID

npm ERR! peerinvalid The package [email protected] does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants chai@>= 2.1.2 < 4
npm ERR! peerinvalid Peer [email protected] wants chai@>= 1.6.1 < 3

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/adrianTheJavaScriptNoob/Documents/Developer/JavaScript/alexa-app-server/examples/apps/my-javascript-app/npm-debug.log

I think npm wants different versions than what I've got installed. I'm eager to avoid turning this into a recursion of muck ups, so I'm posting here.

What would be the best way to clean up the install?

I looked at npm-debug.log and it says this:

0 info it worked if it ends with ok
1 verbose cli [ '/Users/adrianTheJavaScriptNoob/.nvm/v0.10.36/bin/node',
1 verbose cli   '/Users/adrianTheJavaScriptNoob/.nvm/v0.10.36/bin/npm',
1 verbose cli   'install',
1 verbose cli   'chai-json-schema' ]
2 info using [email protected]
3 info using [email protected]
4 warn package.json [email protected] No README data
5 verbose readDependencies using package.json deps
6 verbose cache add [ 'chai-json-schema@^1.6.1', null ]
7 verbose cache add name=undefined spec="chai-json-schema@^1.6.1" args=["chai-json-schema@^1.6.1",null]
8 verbose parsed url { protocol: null,
8 verbose parsed url   slashes: null,
8 verbose parsed url   auth: null,
8 verbose parsed url   host: null,
8 verbose parsed url   port: null,
8 verbose parsed url   hostname: null,
8 verbose parsed url   hash: null,
8 verbose parsed url   search: null,
8 verbose parsed url   query: null,
8 verbose parsed url   pathname: 'chai-json-schema@^1.6.1',
8 verbose parsed url   path: 'chai-json-schema@^1.6.1',
8 verbose parsed url   href: 'chai-json-schema@^1.6.1' }
9 verbose cache add name="chai-json-schema" spec="^1.6.1" args=["chai-json-schema","^1.6.1"]
10 verbose parsed url { protocol: null,
10 verbose parsed url   slashes: null,
10 verbose parsed url   auth: null,
10 verbose parsed url   host: null,
10 verbose parsed url   port: null,
10 verbose parsed url   hostname: null,
10 verbose parsed url   hash: null,
10 verbose parsed url   search: null,
10 verbose parsed url   query: null,
10 verbose parsed url   pathname: '^1.6.1',
10 verbose parsed url   path: '^1.6.1',
10 verbose parsed url   href: '^1.6.1' }
11 verbose addNamed [ 'chai-json-schema', '^1.6.1' ]
12 verbose addNamed [ null, '>=1.6.1-0 <2.0.0-0' ]
13 silly lockFile 34644556-chai-json-schema-1-6-1 chai-json-schema@^1.6.1
14 verbose lock chai-json-schema@^1.6.1 /Users/adrianTheJavaScriptNoob/.npm/34644556-chai-json-schema-1-6-1.lock
15 silly addNameRange { name: 'chai-json-schema',
15 silly addNameRange   range: '>=1.6.1-0 <2.0.0-0',
15 silly addNameRange   hasData: false }
16 verbose request where is /chai-json-schema
17 verbose request registry https://registry.npmjs.org/
18 verbose request id e2d921f702a3d1b4
19 verbose url raw /chai-json-schema
20 verbose url resolving [ 'https://registry.npmjs.org/', './chai-json-schema' ]
21 verbose url resolved https://registry.npmjs.org/chai-json-schema
22 verbose request where is https://registry.npmjs.org/chai-json-schema
23 info trying registry request attempt 1 at 13:00:18
24 verbose etag "A7MEFNDHR2NAP8SJP41PKZK1S"
25 http GET https://registry.npmjs.org/chai-json-schema
26 http 304 https://registry.npmjs.org/chai-json-schema
27 silly registry.get cb [ 304,
27 silly registry.get   { date: 'Mon, 18 Apr 2016 17:00:18 GMT',
27 silly registry.get     via: '1.1 varnish',
27 silly registry.get     'cache-control': 'max-age=300',
27 silly registry.get     etag: '"A7MEFNDHR2NAP8SJP41PKZK1S"',
27 silly registry.get     age: '0',
27 silly registry.get     connection: 'keep-alive',
27 silly registry.get     'x-served-by': 'cache-jfk1035-JFK',
27 silly registry.get     'x-cache': 'MISS',
27 silly registry.get     'x-cache-hits': '0',
27 silly registry.get     'x-timer': 'S1460998818.398706,VS0,VE32',
27 silly registry.get     vary: 'Accept-Encoding' } ]
28 verbose etag https://registry.npmjs.org/chai-json-schema from cache
29 silly addNameRange number 2 { name: 'chai-json-schema',
29 silly addNameRange   range: '>=1.6.1-0 <2.0.0-0',
29 silly addNameRange   hasData: true }
30 silly addNameRange versions [ 'chai-json-schema',
30 silly addNameRange   [ '1.0.2',
30 silly addNameRange     '1.0.3',
30 silly addNameRange     '1.0.4',
30 silly addNameRange     '1.0.5',
30 silly addNameRange     '1.0.7',
30 silly addNameRange     '1.0.10',
30 silly addNameRange     '1.1.0',
30 silly addNameRange     '1.2.0' ] ]
31 silly lockFile 34644556-chai-json-schema-1-6-1 chai-json-schema@^1.6.1
32 silly lockFile 34644556-chai-json-schema-1-6-1 chai-json-schema@^1.6.1
33 error notarget No compatible version found: chai-json-schema@'>=1.6.1-0 <2.0.0-0'
33 error notarget Valid install targets:
33 error notarget ["1.0.2","1.0.3","1.0.4","1.0.5","1.0.7","1.0.10","1.1.0","1.2.0"]
33 error notarget
33 error notarget This is most likely not a problem with npm itself.
33 error notarget In most cases you or one of your dependencies are requesting
33 error notarget a package version that doesn't exist.
34 error System Darwin 15.3.0
35 error command "/Users/adrianTheJavaScriptNoob/.nvm/v0.10.36/bin/node" "/Users/adrianTheJavaScriptNoob/.nvm/v0.10.36/bin/npm" "install" "chai-json-schema"
36 error cwd /Users/adrianTheJavaScriptNoob/Documents/Developer/JavaScript/alexa-app-server/examples/apps/my-javascript-app
37 error node -v v0.10.36
38 error npm -v 1.4.28
39 error code ETARGET
40 verbose exit [ 1, true ]

Update:

I was attempting to use the chai-json-schema JSON package to test that a return value is JSON. I discovered stock chai has a way to test that a return value is JSON, which explains why chai-son-schema hasn't been updated in over a year.:

return expect(value).to.be.json; // tests if it's a json response

Upvotes: 0

Views: 624

Answers (1)

alexmac
alexmac

Reputation: 19617

That error tells you that installed chai package version doesn't satisfy the version required by chai-json-schema.

If you look at package.json of the chai-json-schema package you will see that it requires the following chai version:

"peerDependencies": {
   "chai": ">= 1.6.1 < 3"
}

Check installed chai package version: npm ls --depth=0, I think your version >= 3.

Upvotes: 1

Related Questions