嗨,我已经使用ionic cordova build android --prod --release
这个命令在ionic 4中生成apk了,但是我却收到了这样的错误
enter image description here
这是app.module.ts中的代码,仅在此处显示错误。 我的app.module.ts是
import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { CategoryPage } from '../pages/category/category';
import { CustomPage } from '../pages/custom/custom';
import { NewstuffPage } from '../pages/newstuff/newstuff'
import { ChinesePage } from '../pages/chinese/chinese';
import { ItalianPage } from '../pages/italian/italian';
import { MexicanPage } from '../pages/mexican/mexican';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
@NgModule({
declarations: [
MyApp
],
imports: [
BrowserModule,
CategoryPage,
HomePage,
CustomPage,
ChinesePage,
ItalianPage,
MexicanPage,
NewstuffPage,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
CategoryPage,
HomePage,
CustomPage,
ChinesePage,
ItalianPage,
MexicanPage,
NewstuffPage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
输出我在命令提示符中得到的内容
C:\onlinefood>ionic cordova build android --prod --release
> ionic-app-scripts build --prod --target cordova --platform android
[16:18:00] ionic-app-scripts 3.2.0
[16:18:00] build prod started ...
[16:18:00] clean started ...
[16:18:00] clean finished in 3 ms
[16:18:00] copy started ...
[16:18:01] deeplinks started ...
[16:18:01] deeplinks finished in 71 ms
[16:18:01] ngc started ...
[16:18:16] typescript error
Unexpected directive 'CategoryPage in C:/onlinefood/src/pages/category/category.ts' imported by the module
'AppModule in C:/onlinefood/src/app/app.module.ts'. Please add a @NgModule annotation.
[16:18:16] ionic-app-script task: "build"
[16:18:16] Error: The Angular AoT build failed. See the issues above
Error: The Angular AoT build failed. See the issues above
at C:\onlinefood\node_modules\@ionic\app-scripts\dist\aot\aot-compiler.js:237:55
at step (C:\onlinefood\node_modules\@ionic\app-scripts\dist\aot\aot-compiler.js:32:23)
at Object.next (C:\onlinefood\node_modules\@ionic\app-scripts\dist\aot\aot-compiler.js:13:53)
at fulfilled (C:\onlinefood\node_modules\@ionic\app-scripts\dist\aot\aot-compiler.js:4:58)
at <anonymous>
[ERROR] An error occurred while running subprocess ionic-app-scripts.
ionic-app-scripts build --prod --target cordova --platform android exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.
提前感谢您解决我的问题
答案 0 :(得分:0)
请尝试通过使用命令
更新应用脚本npm install -g @ ionic / app-scripts @ latest --save-dev
然后尝试再次构建。我认为这可能对您有帮助。