Module not found: Error: Can't resolve '@angular/animations'

Module not found: Error: Can't resolve '@angular/animations'

使用 "npm install" 并通过 "npm start" 启动本地服务器后,我开始收到此错误:-

ERROR in ./~/@angular/material/@angular/material.es5.js
Module not found: Error: Can't resolve '@angular/animations' in '/home/ashvini/Desktop/HN-Angular2/node_modules/@angular/material/@angular'
 @ ./~/@angular/material/@angular/material.es5.js 20:0-81
 @ ./src/app/app.module.ts
 @ ./src/main.ts`enter code here`
 @ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts
webpack: Failed to compile.

这与 angular material 设计有关,但我无法理解我需要做什么来解决这个问题。

在 "npm install" 之前工作正常。

app.module 中添加:

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

然后在模块中将其添加到 imports:

imports: [BrowserAnimationsModule]

并删除 @angular/animations 导入语句。

也许通过应用 npm install,您将 Angular 版本从 v.2 更新到 v.4。

更新:

或者将其添加到您的 package.json (选择您需要的版本):

"dependencies": {
    "@angular/animations": "^4.0.1",
}

将此添加到依赖项后,再次应用 npm install

更新 2:

更快的方法:

npm install @angular/animations --save

在 package.json 中删除 (^) "@angular/material": "^2.0.0-beta.2"。在最新的 angualr.material 中,我们遇到了这个错误。

npm install 将安装最新的 Angular 框架,现在是 4.

上面已经有人提到了解决办法

干杯。

我认真搜索了很多然后我发现在我的项目中

node_modules/@angular/

我错误地必须安装文件,由于错误安装一半和命名动画所以当我删除该文件时出现错误 solved.I 认为这可能是由于根目录和项目文件夹中有多个文件。