Angular 2: 找不到模块 '@angular/animations/browser'
Angular 2: Cannot find module '@angular/animations/browser'
我正在尝试安装 Angular2-Toaster (https://github.com/Stabzs/Angular2-Toaster),在示例中我成功安装了 npm install angular2-toaster 并且我可以在没有错误的情况下导入它,但是我怎么看我还需要动画所以我安装了:
npm install '@angular/animations' --save
但是导入模块时出现错误:
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
有:
Cannot find module '@angular/platform-browser/animations'
我也尝试 npm install
和 npm update -D && npm update -S
。
这是我的 app.module.ts:
import {BrowserModule} from '@angular/platform-browser';
import {NgModule, Component} from '@angular/core';
import {HttpModule} from '@angular/http';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {FormBuilder} from '@angular/forms';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; <- errors
import {ToasterModule, ToasterService} from 'angular2-toaster';
import {AppComponent} from './app.component';
... my components
@NgModule({
declarations: [
AppComponent,
... my components
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
BrowserAnimationsModule,
ToasterModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
package.json:
{
"name": "spring-boot-angular2-client",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.json",
"test": "ng test",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@angular/animation": "^4.0.0-beta.8",
"@angular/animations": "^4.4.0-RC.0",
"@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",
"angular2-toaster": "^4.0.1",
"bootstrap": "^3.3.7",
"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"
}
}
您使用的是 Angular v2,没有 BrowserAnimationsModule,该模块是 Angular v4 的一部分。实际上你不需要这个 import
我正在尝试安装 Angular2-Toaster (https://github.com/Stabzs/Angular2-Toaster),在示例中我成功安装了 npm install angular2-toaster 并且我可以在没有错误的情况下导入它,但是我怎么看我还需要动画所以我安装了:
npm install '@angular/animations' --save
但是导入模块时出现错误:
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
有:
Cannot find module '@angular/platform-browser/animations'
我也尝试 npm install
和 npm update -D && npm update -S
。
这是我的 app.module.ts:
import {BrowserModule} from '@angular/platform-browser';
import {NgModule, Component} from '@angular/core';
import {HttpModule} from '@angular/http';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {FormBuilder} from '@angular/forms';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; <- errors
import {ToasterModule, ToasterService} from 'angular2-toaster';
import {AppComponent} from './app.component';
... my components
@NgModule({
declarations: [
AppComponent,
... my components
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
BrowserAnimationsModule,
ToasterModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
package.json:
{
"name": "spring-boot-angular2-client",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.json",
"test": "ng test",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@angular/animation": "^4.0.0-beta.8",
"@angular/animations": "^4.4.0-RC.0",
"@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",
"angular2-toaster": "^4.0.1",
"bootstrap": "^3.3.7",
"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"
}
}
您使用的是 Angular v2,没有 BrowserAnimationsModule,该模块是 Angular v4 的一部分。实际上你不需要这个 import