找不到模块 angular/animations
Cannot find module angular/animations
我在 angular2 中使用 webpack,当我尝试 运行 我的应用程序时,我收到一条错误消息
Cannot find module "@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"
}
我的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'
})
]
};
当我运行像npm start这样的命令时,我得到一个如上所述的错误。
我什至尝试使用此命令安装 angular-animate
npm install angular-animate
这是我收到的错误消息
我也试过用命令
卸载angular-animate
npm uninstall angular-animate
但这对我没有帮助。
@angular/animimations 是在版本 4.0.0(候选发布版)中引入的。你需要更新到 angular4.
看起来像 Angular 2 这是核心的一部分,如 archived documentation:
所示
import {
Component,
Input,
trigger,
state,
style,
transition,
animate
} from '@angular/core';
您走在正确的轨道上,但很接近!您可以在此 discussion here 中看到,动画已从核心中删除。此外,带连字符的名称显然已被取消 - 所以 angular 动画现在是 @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
更新 Typescript
这应该可以解决问题。
如果没有解决问题,我建议您检查您的 json 软件包并确保您在所有核心方面都达到了 4.0现在单独的动画片段。然后,删除您的节点模块文件夹,清除缓存,然后 运行 使用更新包进行全新安装,如下所示:
>$ rm -rf node_modules
>$ npm cache clear
>$ npm install
现在有点忙,很多不同的人对核心功能集做出了很多更改和修复,然后[=39=的其他部分] 紧跟核心,所以我建议您以非常有条理的步骤谨慎地推进您正在进行的任何项目,以便您可以一一解决出现的问题(并且更容易 find/fix)。
希望对您有所帮助!
执行以下步骤使其工作:
npm install @angular/animations@latest --save
import "BrowserAnimationsModule" from "@angular/platform-browser/animations" in your root NgModule(没有这个,你的代码将编译并运行,但动画会触发错误)
在你的组件中使用像这样从新包导入 - " import { trigger, state, style, transition, animate } from '@angular/animations'; "
这对我有用。
我已经完成了这些步骤:
https://github.com/mgechev/angular-seed/issues/1880#issuecomment-290557768
我会引用:
I had the same issue upgrading from 2.0 to 4.0. In the end I was missing the following from my systemjs.config.js:
'@angular/animations':
'npm:@angular/animations/bundles/animations.umd.js',
'@angular/animations/browser':
'npm:@angular/animations/bundles/animations-browser.umd.js',
'@angular/platform-browser/animations':
'npm:@angular/platform-browser/bundles/platform-browser-animations.umd.js',
At first I had the first and third line - everything started working
once I added the second line for @angular/animations/browser.
这对我有用,我可以看到大多数情况都已修复。
您必须像这样导入 angular 动画模块:
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';import {trigger,state,style,animate,transition}from '@angular/animations';
我在 angular2 中使用 webpack,当我尝试 运行 我的应用程序时,我收到一条错误消息
Cannot find module "@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"
}
我的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'
})
]
};
当我运行像npm start这样的命令时,我得到一个如上所述的错误。
我什至尝试使用此命令安装 angular-animate
npm install angular-animate
这是我收到的错误消息
我也试过用命令
卸载angular-animatenpm uninstall angular-animate
但这对我没有帮助。
@angular/animimations 是在版本 4.0.0(候选发布版)中引入的。你需要更新到 angular4.
看起来像 Angular 2 这是核心的一部分,如 archived documentation:
所示
import {
Component,
Input,
trigger,
state,
style,
transition,
animate
} from '@angular/core';
您走在正确的轨道上,但很接近!您可以在此 discussion here 中看到,动画已从核心中删除。此外,带连字符的名称显然已被取消 - 所以 angular 动画现在是 @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
现在有点忙,很多不同的人对核心功能集做出了很多更改和修复,然后[=39=的其他部分] 紧跟核心,所以我建议您以非常有条理的步骤谨慎地推进您正在进行的任何项目,以便您可以一一解决出现的问题(并且更容易 find/fix)。
希望对您有所帮助!
执行以下步骤使其工作:
npm install @angular/animations@latest --save
import "BrowserAnimationsModule" from "@angular/platform-browser/animations" in your root NgModule(没有这个,你的代码将编译并运行,但动画会触发错误)
在你的组件中使用像这样从新包导入 - " import { trigger, state, style, transition, animate } from '@angular/animations'; "
这对我有用。
我已经完成了这些步骤:
https://github.com/mgechev/angular-seed/issues/1880#issuecomment-290557768
我会引用:
I had the same issue upgrading from 2.0 to 4.0. In the end I was missing the following from my systemjs.config.js:
'@angular/animations': 'npm:@angular/animations/bundles/animations.umd.js',
'@angular/animations/browser': 'npm:@angular/animations/bundles/animations-browser.umd.js',
'@angular/platform-browser/animations': 'npm:@angular/platform-browser/bundles/platform-browser-animations.umd.js',At first I had the first and third line - everything started working once I added the second line for @angular/animations/browser.
这对我有用,我可以看到大多数情况都已修复。
您必须像这样导入 angular 动画模块:
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';import {trigger,state,style,animate,transition}from '@angular/animations';