在现有 package.json 中安装新的依赖项

Installing a new dependency in existing package.json

前言: 我是 JavaScript 的新手,我知道这是一个基本问题,但我看到有几种不同的方法可以将依赖项添加到现有 JavaScript 个项目。我检查了几个不同点的文档以确保我不会搞砸它,尽管安装了文件,但我的终端中有一堆东西表明我遇到了问题。

这是我所做的:

我有一个最初安装了 chai 的项目。进一步,我发现我需要测试 JSON 个文件,我发现 Chai 有一个名为 chai-json-schema 的包,所以我仔细检查了安装说明并安装了它。

要安装,我从项目的根目录输入:

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

已记录:

Adrians-Air:my-javascript-app adrianTheJavaScriptNoob$ npm install --save chai-json-schema
npm WARN package.json my-javascript-app@1.0.0 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 chai@3.5.0 does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer chai-as-promised@5.3.0 wants chai@>= 2.1.2 < 4
npm ERR! peerinvalid Peer chai-json-schema@1.2.0 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

我认为 npm 需要与我安装的版本不同的版本。我急于避免将其变成一团糟的递归,所以我在这里发帖。

清理安装的最佳方法是什么?

我查看了 npm-debug.log,上面写着:

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 npm@1.4.28
3 info using node@v0.10.36
4 warn package.json my-javascript-app@1.0.0 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 ]

更新:

我试图使用 chai-json-schema JSON 包来测试 return 值是否为 JSON。我发现股票 chai 有一种方法可以测试 return 的值是 JSON,这解释了为什么 chai-son-schema 已经一年多没有更新了。:

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

该错误告诉您安装的 chai 软件包版本不满足 chai-json-schema 要求的版本。

如果您查看 chai-json-schema 包的 package.json,您会发现它需要以下 chai 版本:

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

检查安装的 chai 包版本:npm ls --depth=0,我认为你的版本 >= 3.