http-loader
http-loader copied to clipboard
Error: parsing json file angular 5
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.
I have the same issue
I've faced the same bug.

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 the same issue but I have Angular 4.3
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/
It is valid. I checked with several tools, including the one you provided.
i have same issue
Check for a trailing
,or attributes not wrapped in quotes... thehttp.getmethod 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?