Core: ng2 translate does not work with webpack

Created on 19 Jul 2017  路  5Comments  路  Source: ngx-translate/core

For reducing the start time of the application, I have configured webpack in my application . But after that ng2 translate is not working and I am getting the error
ERROR Error: Uncaught (in promise): Response with status: 200 for URL: null

"ng2-translate": "^5.0.0",

app.module.ts

export function createTranslateLoader(http: Http) {
    return new TranslateHttpLoader(http, './assets/i18n', '.json');
}
@NgModule({
  declarations: [AppComponent],
  bootstrap: [AppComponent],
imports: [
    NativeScriptModule,
    NativeScriptHttpModule,
    NativeScriptUIListViewModule,
    NativeScriptFormsModule,
    NativeScriptUISideDrawerModule,
    NativeScriptRouterModule,
    NativeScriptRouterModule.forRoot(routes),
    TranslateModule.forRoot({
            provide: TranslateLoader,
            useFactory: (createTranslateLoader),
            deps: [Http]
        })
  ],

In webpack.config.js
I have added

new CopyWebpackPlugin([
            {from: mainSheet},
            {from: "css/**"},
            {from: "fonts/**"},
            {from: "**/*.jpg"},
            {from: "**/*.png"},
            {from: "**/*.xml"},
            **{from: "i18n/*.json"},**
            {from: "**/*.json"},
        ], {ignore: ["App_Resources/**"]}),

Most helpful comment

I had a similar issue a few hours ago, if your translation json is inside the folder app/assets/i18n
add the next line to your CopyWebpackPlugin
{ from: "assets/i18n/*.json" }

All 5 comments

I have updated ng2 translate and now using ng-x- translate but still getting the same issue
"@ngx-translate/core": "^7.0.0",
"@ngx-translate/http-loader": "^0.1.0",

I had a similar issue a few hours ago, if your translation json is inside the folder app/assets/i18n
add the next line to your CopyWebpackPlugin
{ from: "assets/i18n/*.json" }

@Cayan : Tried that too .. still the error is same. Can you please share your app.module.ts

@Shifs the related code from app.module.ts is listed below:

...
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
...
export function createTranslateLoader(http: Http) {
return new TranslateHttpLoader(http);
}

@NgModule({
schemas: [NO_ERRORS_SCHEMA],
imports: [
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [Http]
}
}),
...

@Shifs did you solve this issue ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

briancullinan picture briancullinan  路  3Comments

madoublet picture madoublet  路  3Comments

alkemist picture alkemist  路  3Comments

rbaumi picture rbaumi  路  4Comments

guysan picture guysan  路  4Comments