简体   繁体   English

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

[英]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. 前言:我是JavaScript的新手,我知道这是一个基本问题,但是我看到了几种向现有JavaScript项目添加依赖项的不同方法。 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. 我最初有一个安装了chai的项目。 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. 进一步地,我发现我需要测试JSON文件,并且发现Chai有一个名为chai-json-schema的软件包,因此我仔细检查了安装说明并安装了它。

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 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

I think npm wants different versions than what I've got installed. 我认为npm想要的版本与我安装的版本不同。 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: 我看了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 ]

Update: 更新:

I was attempting to use the chai-json-schema JSON package to test that a return value is JSON. 我试图使用chai-json-schema JSON包来测试返回值是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.: 我发现stock chai可以测试返回值是否为JSON,这解释了为什么chai-son-schema一年多都没有更新了:

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

That error tells you that installed chai package version doesn't satisfy the version required by chai-json-schema . 该错误告诉您,已安装的chai软件包版本不满足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: 如果查看chai-json-schema软件包的package.json ,您将看到它需要以下chai版本:

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

Check installed chai package version: npm ls --depth=0 , I think your version >= 3. 检查已安装的chai软件包版本: npm ls --depth=0 ,我认为您的版本> = 3。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM