我尝试在我的项目中安装Animations。
C:\gtaui>npm install @angular/animations --save
gtaui@0.0.0 C:\gtaui
+-- @angular/animations@4.1.1
`-- UNMET PEER DEPENDENCY @angular/core@2.4.10
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\ch
okidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@
1.1.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}
)
npm WARN @angular/animations@4.1.1 requires a peer of @angular/core@4.1.1 but no
ne was installed.
C:\gtaui>
我在package.json中有了库
{
"name": "gtaui",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"ng": "ng",
"start": "ng serve",
"test": "ng test",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@angular/animations": "^4.1.1",
"@angular/common": "^2.3.1",
"@angular/compiler": "^2.3.1",
"@angular/core": "^2.3.1",
"@angular/forms": "^2.3.1",
"@angular/http": "^2.3.1",
"@angular/platform-browser": "^2.3.1",
"@angular/platform-browser-dynamic": "^2.3.1",
"@angular/router": "^3.3.1",
"core-js": "^2.4.1",
"rxjs": "^5.0.1",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.2"
},
"devDependencies": {
"@angular/compiler-cli": "^2.3.1",
"@types/jasmine": "2.5.38",
"@types/node": "^6.0.42",
"angular-cli": "1.0.0-beta.28.3",
"codelyzer": "~2.0.0-beta.1",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "~4.0.13",
"ts-node": "1.2.1",
"tslint": "^4.3.0",
"typescript": "~2.0.3"
}
}
在我在应用程序模块中添加动画模块之后:
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
我收到错误:
C中的错误:/gtaui/src/app/modules/app.ts(3,41):找不到模块'@ angular / pl atform浏览器/动画。 C中的错误:/gtaui/src/app/modules/app.ts(3,41):找不到模块'@ angular / pl atform浏览器/动画。 webpack:无法编译。
答案 0 :(得分:1)
它给了你一个很好的警告,让你知道:npm WARN @angular/animations@4.1.1 requires a peer of @angular/core@4.1.1 but none was installed.
将package.json更新为
"dependencies": {
"@angular/animations": "^4.1.1",
"@angular/common": "^4.1.1",
"@angular/compiler": "^4.1.1",
"@angular/core": "^4.1.1",
"@angular/forms": "^4.1.1",
"@angular/http": "^4.1.1",
"@angular/platform-browser": "^4.1.1",
"@angular/platform-browser-dynamic": "^4.1.1",
"@angular/router": "^4.1.1",
"core-js": "^2.4.1",
"rxjs": "^5.0.1",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.2"
}
当npm说"需要同伴"确保将其包含在依赖项中。