需要一个对等点,但没有安装
Posted
技术标签:
【中文标题】需要一个对等点,但没有安装【英文标题】:requires a peer but none was installed 【发布时间】:2017-12-04 03:44:12 【问题描述】:我的package.json
看起来像这样
"name": "hello-world",
"version": "1.0.0",
"description": "The Hello World",
"author": "",
"license": "MIT",
"scripts":
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
,
"dependencies":
"@angular/common": "~2.0.1",
"@angular/compiler": "~2.0.1",
"@angular/core": "~2.0.1",
"@angular/http": "~2.0.1",
"@angular/platform-browser": "~2.0.1",
"@angular/platform-browser-dynamic": "~2.0.1",
"@angular/router": "~3.0.1",
"@angular/upgrade": "~2.0.1",
"systemjs": "0.19.39",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.8",
"rxjs": "5.0.0-beta.12",
"zone.js": "^0.6.25",
"angular-in-memory-web-api": "~0.1.1",
"bootstrap": "4.0.0-alpha.4"
,
"devDependencies":
"concurrently": "^3.0.0",
"lite-server": "^2.2.2",
"typescript": "^2.0.3",
"typings": "^1.4.0"
当我运行 npm i
时,它运行成功,但我收到了一些警告。
npm WARN angular-in-memory-web-api@0.1.17 requires a peer of rxjs@5.0.0-rc.4 but none was installed.
npm WARN angular-in-memory-web-api@0.1.17 requires a peer of zone.js@^0.7.2 but none was installed.
我将这些行添加到package.json
"peerDependencies":
"rxjs": "5.0.0-rc.4",
"zone.js": "^0.7.2"
但是当我再次运行 npm i
时,我仍然收到此警告
npm WARN hello-world@1.0.0 requires a peer of rxjs@5.0.0-rc.4 but none was installed.
npm WARN hello-world@1.0.0 requires a peer of zone.js@^0.7.2 but none was installed.
npm WARN angular-in-memory-web-api@0.1.17 requires a peer of rxjs@5.0.0-rc.4 but none was installed.
npm WARN angular-in-memory-web-api@0.1.17 requires a peer of zone.js@^0.7.2 but none was installed.
对主应用程序附加警告。为什么会这样以及如何消除此警告?
【问题讨论】:
What's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?的可能重复 简而言之:您只需将它们作为正常依赖项添加到项目中即可。 你的意思是把它们添加到dependencies
对应的版本?切换到zone.js^0.7.2
导致ERR
和unmet peer dependency zone.js@0.7.8
请求的对等体是 0.7.8 版本,而不是 ^0.7.2。
在我的帖子中,他们需要 ^0.7.2
- 需要 zone.js@^0.7.2 的对等但没有安装 - 但是当我添加它时,它开始需要 0.7.8
【参考方案1】:
我删除node_modules
文件夹并运行npm install
。错误会消失。
【讨论】:
【参考方案2】:TL;DR
Peer Dependencies 是一种特殊的依赖关系——它们被不直接调用它们的包使用,从而给予用户(您)控制权。因此,您必须手动安装这些软件包。
您无需将peerDependencies
添加到您的package.json
。
您看到这些错误的原因是,您的一些依赖项在其package.json
中将rxjs@5.0.0-rc.4
和zone.js@^0.7.2
声明为peerDependencies
。这就是为什么当您在 package.json
中添加 peerDependencies
时,您会收到两次警告。
要了解有关对等依赖项的更多信息,我建议阅读以下内容:
-
Peer Dependencies
What are those PeerDependencies in a NodeJS project?
这个great answer
【讨论】:
以上是关于需要一个对等点,但没有安装的主要内容,如果未能解决你的问题,请参考以下文章
React-native@0.26.3 需要 react@15.0.2 的对等点,但没有安装
npm WARN babel-loader@6.2.8 需要 babel-core@^6.0.0 的对等点,但没有安装
npm WARN jest-react-native@17.0.0 需要 whatwg-fetch@^1.0.0 的对等点,但没有安装
@angular/cdk@5.0.3 需要 @angular/common@~5.1.1 的对等体,但没有安装
karma-jasmine-html-reporter@1.1.0 需要 jasmine@>=3 的对等方,但没有安装。