1、基本准备
卸载本地的ionic2,重装ionic3,更新package.json包,重新npm install(或者cnpm install)。
2、升级过程中遇到的问题
报错: Error: Cannot read property 'filter' of undefined
报错情况:
[12:44:35] ionic-app-scripts 1.3.0
[12:44:35] watch started ...
[12:44:35] build dev started ...
[12:44:35] clean started ...
[12:44:35] clean finished in 1 ms
[12:44:35] copy started ...
[12:44:35] transpile started ...
[12:44:38] transpile finished in 3.13 s
[12:44:38] preprocess started ...
[12:44:38] deeplinks started ...
[12:44:38] ionic-app-script task: "serve"
[12:44:38] Error: Cannot read property 'filter' of undefined
Error: Cannot read property 'filter' of undefined
at new BuildError (/Users/bodhi/Projects/snapshare/node_modules/@ionic/app-scripts/dist/util/errors.js:16:28)
...
查找原因:是app.module.ts文件里的@NgModule出现了问题。
解决方法:先需要修改app.module.ts文件
imports里面一定要导入BrowserModule。
报错:webpackJsonp is not defined
报错情况:
查找原因:缺少文件文件vendor.js的引用
解决方法:修改index.js文件
<script src="build/polyfills.js"></script>
<script src="build/vendor.js"></script> // 如果没有是需要新添加的
<script src="build/main.js"></script>
报错:No Provider for setting
报错情况:
查找原因:没有在app.module.ts中的providers中注册
解决办法:
@NgModule({
declarations: [
AppComponent,
],
imports: [
Modules,
BrowserModule,
IonicModule.forRoot(AppComponent, {
}),
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [Http]
}
}),
],
bootstrap: [IonicApp],
entryComponents: [
AppComponent,
],
providers: [
{ provide: ErrorHandler, useClass: IonicErrorHandler },
Api,
Common,
Settings,
InAppBrowser,
SplashScreen
]
})
报警告:Unused Import
解决办法:
在项目根目录找到 tslint.json 文件,查找no-duplicate-variable和no-unused-variable属性改为false即可。
"rules": {
"no-duplicate-variable": true,
"no-unused-variable": [
false
]
}