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

时间:2016-04-18 17:37:07

标签: javascript json node.js npm chai

前言:我是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包来测试返回值是否为JSON。我发现库存chai有一种方法可以测试返回值是否为JSON,这解释了为什么chai-son-schema在一年内没有更新。

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

1 个答案:

答案 0 :(得分:1)

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

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

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

检查已安装的chai软件包版本:npm ls --depth=0,我认为您的版本&gt; = 3.