我已经安装了支持Angular 4.0.1的Ionic 3.6,因为我想重用一些我已经为桌面应用开发的代码。 我面临的问题是,当我使用
创建一个新项目时ionic start newProject
它使用Angular 5,如您在下面的package.json中所见,在那里您还可以看到angular-ionic 3.9.2是依赖项。
如何使用Angular 4.0.1创建新项目?这也很重要,因为当我使用 ionic cordova运行android 测试项目然后编辑文件时,连接会因错误而中断。
谢谢。
{
"name": "my5thproject",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"@angular/common": "5.0.0",
"@angular/compiler": "5.0.0",
"@angular/compiler-cli": "5.0.0",
"@angular/core": "5.0.0",
"@angular/forms": "5.0.0",
"@angular/http": "5.0.0",
"@angular/platform-browser": "5.0.0",
"@angular/platform-browser-dynamic": "5.0.0",
"@ionic-native/core": "4.3.2",
"@ionic-native/splash-screen": "4.3.2",
"@ionic-native/status-bar": "4.3.2",
"@ionic/storage": "2.1.3",
"ionic-angular": "3.9.2",
"ionicons": "3.0.0",
"rxjs": "5.5.2",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.18"
},
"devDependencies": {
"@ionic/app-scripts": "3.1.0",
"@ionic/cli-plugin-ionic-angular": "1.4.1",
"ionic": "3.6.0",
"typescript": "2.4.2"
},
"description": "An Ionic project"
}
答案 0 :(得分:1)
受Suresh答案的启发,最终的解决方案涉及不同的步骤:
npm install
npm install rxjs@5.4.0
npm install zone.js@0.8.12
npm install --save-dev @ionic/cli-plugin-cordova@1.4.1
<preference name="android-minSdkVersion" value="19" />
throw er; // Unhandled 'error' event
”,我用命令解决了
npm i -D -E ws@3.3.2
这是一段漫长的旅程,但我终于做到了。也感谢关于SO的许多其他答案。知道是否有更直接的解决方案将很有趣。
package.json
{
"name": "my5thproject",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"@angular/common": "4.1.3",
"@angular/compiler": "4.1.3",
"@angular/compiler-cli": "4.1.3",
"@angular/core": "4.1.3",
"@angular/forms": "4.1.3",
"@angular/http": "4.1.3",
"@angular/platform-browser": "4.1.3",
"@angular/platform-browser-dynamic": "4.1.3",
"@ionic-native/core": "4.3.2",
"@ionic-native/splash-screen": "4.3.2",
"@ionic-native/status-bar": "4.3.2",
"@ionic/storage": "2.1.3",
"ajv": "^6.5.5",
"cordova-android": "7.1.1",
"cordova-plugin-device": "^1.1.4",
"cordova-plugin-ionic-webview": "^1.2.1",
"cordova-plugin-splashscreen": "^4.0.3",
"cordova-plugin-whitelist": "^1.3.1",
"ionic-angular": "3.6.0",
"ionic-plugin-keyboard": "^2.2.1",
"ionicons": "3.0.0",
"rxjs": "^5.4.0",
"sw-toolbox": "3.6.0",
"zone.js": "^0.8.12"
},
"devDependencies": {
"@ionic/app-scripts": "3.1.0",
"@ionic/cli-plugin-cordova": "^1.4.1",
"@ionic/cli-plugin-ionic-angular": "1.4.1",
"ionic": "3.6.0",
"typescript": "2.3.4",
"ws": "3.3.2"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"ionic-plugin-keyboard": {},
"cordova-plugin-whitelist": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-ionic-webview": {}
},
"platforms": [
"android"
]
}
}
答案 1 :(得分:0)
您应该使用3的最新版本,即3.9.2,它将具有性能和错误修复。您为3.6编写的代码应适用于3.9.1。请尝试将其集成。如果仍然要使用特定版本。您可以手动更新package.json文件。
{
"name": "my5thproject",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"@angular/common": "4.0.1",
"@angular/compiler": "4.0.1",
"@angular/compiler-cli": "4.0.1",
"@angular/core": "4.0.1",
"@angular/forms": "4.0.1",
"@angular/http": "4.0.1",
"@angular/platform-browser": "4.0.1",
"@angular/platform-browser-dynamic": "4.0.1",
"@ionic-native/core": "4.3.2",
"@ionic-native/splash-screen": "4.3.2",
"@ionic-native/status-bar": "4.3.2",
"@ionic/storage": "2.1.3",
"ionic-angular": "3.6.0",
"ionicons": "3.0.0",
"rxjs": "5.5.2",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.18"
},
"devDependencies": {
"@ionic/app-scripts": "3.1.0",
"@ionic/cli-plugin-ionic-angular": "1.4.1",
"ionic": "3.6.0",
"typescript": "2.4.2"
},
"description": "An Ionic project"
}
更新package.json之后。尝试删除node_modules文件夹并运行'npm install'。