Core: Getting NOT FOUND Error in production build

Created on 24 Sep 2017  路  5Comments  路  Source: ngx-translate/core

**I'm submitting a but report.

[*] bug report => check the FAQ and search github for a similar issue or PR before submitting
[ ] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request

Current behavior
Normally it works great. But when I build for production then I always get this error:
GET http://localhost/assets/i18n/es.json 404 (Not Found)
But my project is in this location:
http://localhost/project/

Expected/desired behavior
It should normally as it works during development.

Reproduction of the problem
This issue can be reproduced if app is built using this command:
ng build --prod --aot=false

I really appreciate to get any help in this case.

Environment:

  • ngx-translate version: "8.0.0"
  • Angular version: "4.2.4"

  • Browser: [all ]

Most helpful comment

My fault ;(

In app.modules.ts i had to make a change (as mentioned in the docs):

export function HttpLoaderFactory(http: HttpClient) {
  return new TranslateHttpLoader(http);
}
export function HttpLoaderFactory(http: HttpClient) {
  return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}

All 5 comments

I am getting the same error for android:

cli packages: (C:\Users\nowrap\AppData\Roaming\npm\node_modules)

    @ionic/cli-utils  : 1.19.0
    ionic (Ionic CLI) : 3.19.0

global packages:

    cordova (Cordova CLI) : 7.1.0

local packages:

    @ionic/app-scripts : 3.1.2
    Cordova Platforms  : android 6.4.0
    Ionic Framework    : ionic-angular 3.9.2

System:

    Node : v8.6.0
    npm  : 5.3.0
    OS   : Windows 10

Environment Variables:

    ANDROID_HOME : not set

Misc:

    backend : pro

Looking into the chrome remote tools it seems to be a path issue:
file:///android_asset/www/assets/fonts/roboto-regular.woff2
file:///assets/i18n/de.json

My fault ;(

In app.modules.ts i had to make a change (as mentioned in the docs):

export function HttpLoaderFactory(http: HttpClient) {
  return new TranslateHttpLoader(http);
}
export function HttpLoaderFactory(http: HttpClient) {
  return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}

It does not work for me, when I make an NG BUILD and I deploy it in AZURE it does not work

Environment:

"@ngx-translate/core": "^10.0.1"
"@ngx-translate/http-loader": "^3.0.1"
"@angular/core": "^7.2.2",
Browser: [all ]

@Hansel03 some problem for me. Have you solved it?

Thanks

Hi @Nik1990 my configuration is

import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
export function HttpLoaderFactory(http: HttpClient) {
  return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}
imports: [
TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: HttpLoaderFactory,
        deps: [HttpClient]
      }
    }
]

and my angular.json

"assets": [
     "src/assets"
 ]
Was this page helpful?
0 / 5 - 0 ratings