ngx-translate / http-loader

A loader for ngx-translate that loads translations with http calls
MIT License
193 stars 69 forks source link

Error: parsing json file angular 5 #37

Open andrei-ga opened 6 years ago

andrei-ga commented 6 years ago

I just updated to Angular 5. I am using asp-prerendering from .Net Core 2 feature. I import the plugin using

        TranslateModule.forRoot({
            loader: {
                provide: TranslateLoader,
                useFactory: (createTranslateLoader),
                deps: [HttpClient, [ORIGIN_URL]]
            }
        }),

and

export function createTranslateLoader(http: HttpClient, baseHref: string) {
    // Temporary Azure hack
    if (baseHref === null && typeof window !== 'undefined') {
        baseHref = window.location.origin;
    }
    // i18n files are in `wwwroot/assets/`
    return new TranslateHttpLoader(http, `${baseHref}/assets/i18n/`, '.json');
}

I am receiving the following error: NodeInvocationException: Http failure during parsing for http://localhost:50475/assets/i18n/en.json

If I disable pre-rendering or I don't import ngx-translate plugin, everything works.

dobrinsky commented 6 years ago

I have the same issue

Jacooscript commented 6 years ago

I've faced the same bug. image

switch120 commented 6 years ago

Check for a trailing , or attributes not wrapped in quotes... the http.get method is pretty picky about proper JSON syntax. I had the same issue until I (finally) found the one lone trailing comma that was causing this non-descript error. HTH!

Rabeata commented 6 years ago

I have the same issue but I have Angular 4.3

switch120 commented 6 years ago

Try using a tool to validate your JSON - that was my issue, super picky formatting; no trailing commas, wrap all attribute names in quotes, etc. Try this: https://jsonlint.com/

andrei-ga commented 6 years ago

It is valid. I checked with several tools, including the one you provided.

abeel50 commented 4 years ago

i have same issue

abeel50 commented 4 years ago

Check for a trailing , or attributes not wrapped in quotes... the http.get method is pretty picky about proper JSON syntax. I had the same issue until I (finally) found the one lone trailing comma that was causing this non-descript error. HTH!

I have checked already, but there's not a typing error. will some one guide me?