Angular 2 路由器动画 - 找不到模块'@angular/platform-browser/animations'
Augular 2 Router Animation - Cannot find module '@angular/platform-browser/animations'
我一直在关注 Angular 2 路由和导航示例,可以在此 link 找到:https://plnkr.co/edit/I4ArEQTniO7MJtfzpBWl?p=info。
当我 运行 编译器时,我收到错误消息:"client/app/app.module.ts(5,41): error TS2307: Cannot find module '@angular/platform-browser/animations'."
根据我的 systemjs.config.js(如下所示),我希望模块“@angular/platform-browser/animations”是文件,"platform-browser-animations.umd.js" 位于 node_modules/@ angular/platform-browser/bundles,但它不存在。
//systemjs.config.js
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',
'@angular/animations': 'npm:@angular/animations/bundles/animations.umd.js',
'@angular/animations/browser': 'npm:@angular/animations/bundles/animations-browser.umd.js',
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser/animations': 'npm:@angular/platform-browser/bundles/platform-browser-animations.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/router/upgrade': 'npm:@angular/router/bundles/router-upgrade.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
'@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
'@angular/upgrade/static': 'npm:@angular/upgrade/bundles/upgrade-static.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
//app: {
// main: './main.js',
// defaultExtension: 'js'
//},
client: {
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
}
}
});
})(this);
我尝试使用 npm 安装缺少的框架,但收到未满足的依赖项错误消息:
+-- UNMET PEER DEPENDENCY @angular/common@2.4.8
+-- UNMET PEER DEPENDENCY @angular/core@2.4.8
`-- UNMET PEER DEPENDENCY @angular/platform-browser@2.4.10
然后我尝试安装依赖版本,但继续收到未满足的依赖消息。
>npm install @angular/common@2.4.8 @angular/core@2.4.8 @angular/platform-browser@2.4.10 --save
我注意到一个警告,指示我应该安装 Angular 4。
npm WARN @angular/animations@4.0.0 requires a peer of @angular/core@4.0.0 but no
ne was installed.
我好像安装了 animations 4.0,它需要我不想安装的 core 4.0。我是否需要卸载 animations 4.0 并安装较早版本的 animations?我的 package.json 文件在下面。
//package.json
{
"name": "angular-quickstart",
"version": "1.0.0",
"description": "QuickStart package.json from the documentation, supplemented with testing support",
"scripts": {
"build": "tsc -p client/",
"build:watch": "tsc -p client/ -w",
"build:e2e": "tsc -p e2e/",
"serve:e2e": "lite-server -c=bs-config.e2e.json",
"prestart": "npm run build",
"start": "npm run build:watch",
"pree2e": "npm run build:e2e",
"e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --kill-others --success first",
"preprotractor": "webdriver-manager update",
"protractor": "protractor protractor.config.js",
"pretest": "npm run build",
"test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"",
"pretest:once": "npm run build",
"test:once": "karma start karma.conf.js --single-run",
"lint": "tslint ./client/**/*.ts -t verbose"
},
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
"@angular/animations": "^4.0.0",
"@angular/common": "^2.4.8",
"@angular/compiler": "~2.4.0",
"@angular/core": "^2.4.8",
"@angular/forms": "~2.4.0",
"@angular/http": "~2.4.0",
"@angular/platform-browser": "^2.4.10",
"@angular/platform-browser-dynamic": "~2.4.0",
"@angular/router": "~3.4.0",
"angular-animate": "^1.6.3",
"angular-in-memory-web-api": "~0.2.4",
"body-parser": "^1.17.0",
"bootstrap": "^3.3.7",
"cookie-parser": "^1.4.3",
"core-js": "^2.4.1",
"ejs": "^2.5.6",
"express": "^4.15.0",
"express-session": "^1.15.1",
"jade": "^1.11.0",
"jquery": "^3.1.1",
"mongoose": "^4.8.5",
"morgan": "^1.8.1",
"passport": "^0.3.2",
"passport-local": "^1.0.0",
"rxjs": "5.0.1",
"stylus": "^0.54.5",
"systemjs": "0.19.40",
"toastr": "^2.1.2",
"zone.js": "^0.7.4"
},
"devDependencies": {
"concurrently": "^3.2.0",
"lite-server": "^2.2.2",
"typescript": "~2.0.10",
"canonical-path": "0.0.2",
"tslint": "^3.15.1",
"lodash": "^4.16.4",
"jasmine-core": "~2.4.1",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~4.0.14",
"rimraf": "^2.5.4",
"@types/node": "^6.0.46",
"@types/jasmine": "2.5.36"
},
"repository": {}
}
看起来问题可能与我的动画版本有关?如果您同意,如何卸载现有版本以及我应该安装与我拥有的@angular/core 版本兼容的版本,2.4.8。如果这不是问题,我该如何安装丢失的文件@angular/platform-browser/bundles/platform-browser-animations.umd.js?
研究了几个小时后,我找不到与我的 @angular/core 版本兼容的 @angular/animations 版本,运行 从 2.4.0-2.4 开始.8.我阅读了这个 post、 的答案。这个 post 表示 angular 2 除了路由器之外的所有模块都是相同的版本所以我将 @angular/animations 2.4.8 插入我的 package.json 并将所有版本更改为 2.4 .8 包括动画条目,因为我想确保我没有遗漏任何东西。然后我 运行 npm install 并且这在动画版本上失败了。
我终于找到了这个post; http://angularjs.blogspot.com/ 更新到 Angular 4.0。 post 还特别提到了我一直缺少但仅在升级后可用的动画模块。我按照 windows 的简单更新说明操作,我的应用程序现在 运行 正常。我的应用程序与指南中的 plunker 示例非常相似。根据 post,如果你是 运行 Angular 2.x.x 那么这应该向后兼容大多数应用程序。以下是升级说明。
正在更新到 4.0.0
更新到 4 就像将 Angular 依赖项更新到最新版本一样简单,并仔细检查是否需要动画。这适用于大多数用例。
在 Linux/Mac 上:
npm install @angular/{common,compiler,compiler-cli,core,forms,http,platform-browser,platform-browser-dynamic,platform-server,router,animations}@latest typescript @latest --保存
在 Windows:
npm install @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @ angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest @angular/animations@latest typescript @latest --保存
尝试以下步骤
第一步
$ rm -rf node_modules
$ npm cache clear
步骤-2
$ npm install @angular/animations@latest --save
$ npm install
对我有用
我一直在关注 Angular 2 路由和导航示例,可以在此 link 找到:https://plnkr.co/edit/I4ArEQTniO7MJtfzpBWl?p=info。
当我 运行 编译器时,我收到错误消息:"client/app/app.module.ts(5,41): error TS2307: Cannot find module '@angular/platform-browser/animations'."
根据我的 systemjs.config.js(如下所示),我希望模块“@angular/platform-browser/animations”是文件,"platform-browser-animations.umd.js" 位于 node_modules/@ angular/platform-browser/bundles,但它不存在。
//systemjs.config.js
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',
'@angular/animations': 'npm:@angular/animations/bundles/animations.umd.js',
'@angular/animations/browser': 'npm:@angular/animations/bundles/animations-browser.umd.js',
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser/animations': 'npm:@angular/platform-browser/bundles/platform-browser-animations.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/router/upgrade': 'npm:@angular/router/bundles/router-upgrade.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
'@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
'@angular/upgrade/static': 'npm:@angular/upgrade/bundles/upgrade-static.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
//app: {
// main: './main.js',
// defaultExtension: 'js'
//},
client: {
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
}
}
});
})(this);
我尝试使用 npm 安装缺少的框架,但收到未满足的依赖项错误消息:
+-- UNMET PEER DEPENDENCY @angular/common@2.4.8
+-- UNMET PEER DEPENDENCY @angular/core@2.4.8
`-- UNMET PEER DEPENDENCY @angular/platform-browser@2.4.10
然后我尝试安装依赖版本,但继续收到未满足的依赖消息。
>npm install @angular/common@2.4.8 @angular/core@2.4.8 @angular/platform-browser@2.4.10 --save
我注意到一个警告,指示我应该安装 Angular 4。
npm WARN @angular/animations@4.0.0 requires a peer of @angular/core@4.0.0 but no
ne was installed.
我好像安装了 animations 4.0,它需要我不想安装的 core 4.0。我是否需要卸载 animations 4.0 并安装较早版本的 animations?我的 package.json 文件在下面。
//package.json
{
"name": "angular-quickstart",
"version": "1.0.0",
"description": "QuickStart package.json from the documentation, supplemented with testing support",
"scripts": {
"build": "tsc -p client/",
"build:watch": "tsc -p client/ -w",
"build:e2e": "tsc -p e2e/",
"serve:e2e": "lite-server -c=bs-config.e2e.json",
"prestart": "npm run build",
"start": "npm run build:watch",
"pree2e": "npm run build:e2e",
"e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --kill-others --success first",
"preprotractor": "webdriver-manager update",
"protractor": "protractor protractor.config.js",
"pretest": "npm run build",
"test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"",
"pretest:once": "npm run build",
"test:once": "karma start karma.conf.js --single-run",
"lint": "tslint ./client/**/*.ts -t verbose"
},
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
"@angular/animations": "^4.0.0",
"@angular/common": "^2.4.8",
"@angular/compiler": "~2.4.0",
"@angular/core": "^2.4.8",
"@angular/forms": "~2.4.0",
"@angular/http": "~2.4.0",
"@angular/platform-browser": "^2.4.10",
"@angular/platform-browser-dynamic": "~2.4.0",
"@angular/router": "~3.4.0",
"angular-animate": "^1.6.3",
"angular-in-memory-web-api": "~0.2.4",
"body-parser": "^1.17.0",
"bootstrap": "^3.3.7",
"cookie-parser": "^1.4.3",
"core-js": "^2.4.1",
"ejs": "^2.5.6",
"express": "^4.15.0",
"express-session": "^1.15.1",
"jade": "^1.11.0",
"jquery": "^3.1.1",
"mongoose": "^4.8.5",
"morgan": "^1.8.1",
"passport": "^0.3.2",
"passport-local": "^1.0.0",
"rxjs": "5.0.1",
"stylus": "^0.54.5",
"systemjs": "0.19.40",
"toastr": "^2.1.2",
"zone.js": "^0.7.4"
},
"devDependencies": {
"concurrently": "^3.2.0",
"lite-server": "^2.2.2",
"typescript": "~2.0.10",
"canonical-path": "0.0.2",
"tslint": "^3.15.1",
"lodash": "^4.16.4",
"jasmine-core": "~2.4.1",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~4.0.14",
"rimraf": "^2.5.4",
"@types/node": "^6.0.46",
"@types/jasmine": "2.5.36"
},
"repository": {}
}
看起来问题可能与我的动画版本有关?如果您同意,如何卸载现有版本以及我应该安装与我拥有的@angular/core 版本兼容的版本,2.4.8。如果这不是问题,我该如何安装丢失的文件@angular/platform-browser/bundles/platform-browser-animations.umd.js?
研究了几个小时后,我找不到与我的 @angular/core 版本兼容的 @angular/animations 版本,运行 从 2.4.0-2.4 开始.8.我阅读了这个 post、
我终于找到了这个post; http://angularjs.blogspot.com/ 更新到 Angular 4.0。 post 还特别提到了我一直缺少但仅在升级后可用的动画模块。我按照 windows 的简单更新说明操作,我的应用程序现在 运行 正常。我的应用程序与指南中的 plunker 示例非常相似。根据 post,如果你是 运行 Angular 2.x.x 那么这应该向后兼容大多数应用程序。以下是升级说明。
正在更新到 4.0.0
更新到 4 就像将 Angular 依赖项更新到最新版本一样简单,并仔细检查是否需要动画。这适用于大多数用例。
在 Linux/Mac 上:
npm install @angular/{common,compiler,compiler-cli,core,forms,http,platform-browser,platform-browser-dynamic,platform-server,router,animations}@latest typescript @latest --保存
在 Windows:
npm install @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @ angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest @angular/animations@latest typescript @latest --保存
尝试以下步骤
第一步
$ rm -rf node_modules
$ npm cache clear
步骤-2
$ npm install @angular/animations@latest --save
$ npm install
对我有用