找不到模块角度/动画

Lij*_*raj 22 webpack angular angular-animations

我在angular2中使用webpack,当我尝试运行我的应用程序时,我得到一个错误说明

找不到模块"@ angular/animations"

的package.json

{
  "name": "angular-quickstart",
  "version": "1.0.0",
  "description": "QuickStart package.json from the documentation, supplemented with testing support",
  "scripts": {
    "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
    "e2e": "tsc && concurrently \"http-server -s\" \"protractor protractor.config.js\" --kill-others --success first",
    "lint": "tslint ./app/**/*.ts -t verbose",
    "lite": "lite-server",
    "pree2e": "webdriver-manager update",
    "test": "tsc && concurrently \"tsc -w\" \"karma start karma.conf.js\"",
    "test-once": "tsc && karma start karma.conf.js --single-run",
    "tsc": "tsc",
    "tsc:w": "tsc -w"
  },
  "keywords": [],
  "author": "",
  "license": "MIT",
  "dependencies": {
    "@angular/common": "~2.4.0",
    "@angular/compiler": "~2.4.0",
    "@angular/core": "~2.4.0",
    "@angular/forms": "~2.4.0",
    "@angular/http": "~2.4.0",
    "@angular/platform-browser": "~2.4.0",
    "@angular/platform-browser-dynamic": "~2.4.0",
    "@angular/router": "~3.4.0",
    "angular-in-memory-web-api": "~0.2.4",
    "core-js": "^2.4.1",
    "rxjs": "5.0.1",
    "systemjs": "0.19.40",
    "zone.js": "^0.7.4"
  },
  "devDependencies": {
    "awesome-typescript-loader": "^3.1.2",
    "canonical-path": "0.0.2",
    "concurrently": "^3.1.0",
    "html-webpack-plugin": "^2.28.0",
    "http-server": "^0.9.0",
    "karma": "^1.3.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "lite-server": "^2.2.2",
    "lodash": "^4.16.4",
    "primeng": "^4.0.0-rc.1",
    "protractor": "~4.0.14",
    "reflect-metadata": "^0.1.10",
    "rimraf": "^2.5.4",
    "tslint": "^3.15.1",
    "typescript": "~2.0.10",
    "typings": "^2.1.0",
    "webpack": "^2.2.1"
  },
  "repository": {},
  "main": "index.js"
}
Run Code Online (Sandbox Code Playgroud)

我的webpack.config.js文件是

var htmlWebPack = require('html-webpack-plugin');

module.exports = {
    entry: "./app/main.ts",
    output: {
        path: 'dist',
        filename: "bundle.js"
    },
    module: {
        loaders: [
          {
              test: /\.tsx?$/,
              loader: 'awesome-typescript-loader'
          }
        ]
    },
    plugins: [
    new htmlWebPack({
        template: './index.html'
    })
    ]
};
Run Code Online (Sandbox Code Playgroud)

当我像npm start一样运行命令时,我得到了如上所述的错误.

更新1

我甚至尝试使用此命令安装angular-animate

npm安装angular-animate

这是我得到的错误消息 在此输入图像描述 我还尝试使用命令卸载angular-animate

npm卸载angular-animate

但它没有帮助我:(

小智 42

执行以下步骤以使其工作:

  1. npm install @ angular/animations @ latest --save

  2. 从根NgModule中的"@ angular/platform-b​​rowser/animations"导入"BrowserAnimationsModule"(如果没有这个,你的代码将编译并运行,但动画会触发错误)

  3. 在您的组件中,使用从新包中导入,例如"@ angular/animations"中的"import {trigger,state,style,transition,animate}";

这对我有用.


weo*_*dev 5

你是在正确的轨道上,但只是关闭!您可以在此讨论中看到,动画是从核心中取出的.此外,带连字符的名字显然已被删除 - 所以角度动画现在是@ ​​angular/animations,就像@ angular/angular-cli已成为@ angular/cli一样.

因此,为了(希望)解决您的问题 - 您应该执行以下操作:

更新到项目中的Angular 4.您将需要运行才能做到以下几点:npm install @angular/{common,compiler,compiler-cli,core,forms,http,platform-browser,platform-browser-dynamic,platform-server,router,animations}@latest --save您还需要更新打字稿npm install typescript@latest --save

这应该够了吧.

如果它不能解决问题,我建议检查你的json包,并确保你在所有核心方面以及现在单独的动画片段中提升到4.0.然后,删除节点模块文件夹,清除缓存,并使用更新包运行全新安装,如下所示:

>$  rm -rf node_modules
>$  npm cache clear
>$  npm install
Run Code Online (Sandbox Code Playgroud)

现在有点忙乱,很多不同的人为核心功能集做出了很多改变和修复,然后 Angular的其他部分被核心所吸引,所以我建议你仔细研究任何项目你以非常有条理的步骤开启,以便您可以解决逐个出现的问题(并且更容易找到/修复).

希望这可以帮助!


Sal*_*mov 5

您必须像这样导入角度动画模块:

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';import {trigger,state,style,animate,transition}from '@angular/animations';
Run Code Online (Sandbox Code Playgroud)