【发布时间】:2018-10-23 04:50:09
【问题描述】:
我在 ionic 3.9.2 下使用延迟加载的 ngx-translate (v9) 遇到了一些困难。在我运行“buid --prod”之前,浏览器中的一切正常。构建过程的 npc 部分(我认为是 AOT 编译)报告 TranslateLoader 和 TranslatePipe 的“未知标识符”。
虽然我关注了ngx tutorial by ionic,翻阅了ngx-translate和StackOverflow的github,但没有找到类似问题的讨论。因此,我想寻求帮助。
当我运行 ionic cordova build ios --prod 时出现以下错误(请注意第一行,显示 TranslateLoader 和 TranslatePipe 的问题):
Error: Internal error: unknown identifier [{"filePath":"..../node_modules/@ngx-translate/core/core.d.ts","name":"TranslateLoader","members":[]},{"filePath":"..../node_modules/@ngx-translate/core/core.d.ts","name":"TranslatePipe","members":[]}]
at Object.importExpr$$1 [as importExpr] (..../node_modules/@angular/compiler/bundles/compiler.umd.js:31063:23)
at tokenExpr (..../node_modules/@angular/compiler/bundles/compiler.umd.js:20063:39)
at providerDef (..../node_modules/@angular/compiler/bundles/compiler.umd.js:19966:20)
at ..../node_modules/@angular/compiler/bundles/compiler.umd.js:20188:77
at Array.map (<anonymous>)
at NgModuleCompiler.compile (..../node_modules/@angular/compiler/bundles/compiler.umd.js:20188:44)
at AotCompiler._compileModule (..../node_modules/@angular/compiler/bundles/compiler.umd.js:30956:32)
at ..../node_modules/@angular/compiler/bundles/compiler.umd.js:30838:66
at Array.forEach (<anonymous>)
at AotCompiler._compileImplFile (..../node_modules/@angular/compiler/bundles/compiler.umd.js:30838:19)
[11:14:07] copy finished in 9.27 s
这是我的 app.module.ts
...
import { HttpClient, HttpClientModule } from "@angular/common/http";
import { TranslateLoader, TranslateModule } from "@ngx-translate/core";
import { TranslateHttpLoader } from "@ngx-translate/http-loader";
...
@NgModule({
declarations: [
MyApp,
],
imports: [
TranslateModule.forRoot({
loader: {
provide: [TranslateLoader],
useFactory: (HttpLoaderFactory),
deps: [HttpClient]
}
}),
IonicModule.forRoot(MyApp,{
preloadModules: true,
}),
BrowserModule,
HttpClientModule,
BrowserAnimationsModule,
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
],
providers: [SplashScreen, Keyboard, StatusBar, {provide: ErrorHandler, useClass: IonicErrorHandler}, AuthService]
})
...
package.json:
"@ngx-translate/core": "^9.1.1",
"@ngx-translate/http-loader": "^2.0.1", // 3rd version gives the same error.
然后,我在应用程序中将 ngx-translate 导入为 .forChild({...}),并使用相同的导出函数 HttpLoaderFactory()。
最奇怪的是,当我改变启动时
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: (HttpLoaderFactory),
deps: [HttpClient]
}
}),
to(以数组形式提供 TranslateLoader)
TranslateModule.forRoot({
loader: {
provide: [TranslateLoader],
useFactory: (HttpLoaderFactory),
deps: [HttpClient]
}
}),
错误消息变短,TranslatePipe 的问题消失了:
Error: Internal error: unknown identifier [{"filePath":".../node_modules/@ngx-translate/core/core.d.ts","name":"TranslateLoader","members":[]}]
at Object.importExpr$$1 [as importExpr] (.../node_modules/@angular/compiler/bundles/compiler.umd.js:31063:23)
at tokenExpr (.../node_modules/@angular/compiler/bundles/compiler.umd.js:20063:39)
at providerDef (.../node_modules/@angular/compiler/bundles/compiler.umd.js:19966:20)
at .../node_modules/@angular/compiler/bundles/compiler.umd.js:20188:77
at Array.map (<anonymous>)
at NgModuleCompiler.compile (.../node_modules/@angular/compiler/bundles/compiler.umd.js:20188:44)
at AotCompiler._compileModule (.../node_modules/@angular/compiler/bundles/compiler.umd.js:30956:32)
at .../node_modules/@angular/compiler/bundles/compiler.umd.js:30838:66
at Array.forEach (<anonymous>)
at AotCompiler._compileImplFile (.../node_modules/@angular/compiler/bundles/compiler.umd.js:30838:19)
你能帮忙吗?
最好的问候
雅库布
【问题讨论】:
标签: angular cordova ionic3 angular2-aot ngx-translate