Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'indexOf' of undefined - Universal + localize-router + ngx-translate Angular5 #135

Open
albertsanchez opened this issue Jul 13, 2018 · 3 comments
Milestone

Comments

@albertsanchez
Copy link

Error with Angular Universal and angular 5.2.11.
When I run "run serve: ssr" and I go to the browser this error appears

Current behavior

ERROR { Error: Uncaught (in promise): TypeError: Cannot read property 'indexOf' of undefined
TypeError: Cannot read property 'indexOf' of undefined
at TranslateService.getBrowserLang (project/dist/server.js:37892:25)
at ManualParserLoader.LocalizeParser._getBrowserLang (/project/dist/server.js:53678:55)
at ManualParserLoader.LocalizeParser.init (/project/dist/server.js:53502:32)
at /project/dist/server.js:53825:19

Environment


//package.json scripts
"scripts": {
    "ng": "ng",
    "build": "ng build --prod",
    "start": "ng serve",
    "test": "ng test",
    "lint": "tslint ./src/**/*.ts -t verbose",
    "e2e": "ng e2e",
    "extract": "ng xi18n --outputPath=src/locale",
    "build:ssr": "npm run build:client-and-server-bundles && npm run webpack:server",
    "serve:ssr": "node dist/server.js",
    "build:client-and-server-bundles": "ng build --prod && ng build --prod --app 1 --output-hashing=false",
    "webpack:server": "webpack --config webpack.config.js --progress --colors"
}

ngx-translate version: 8.0.0
Angular version: 5.2.11

 
For Tooling issues:
- Node version: 8.11.3
- Platform:  Mac

@dz-rep
Copy link

dz-rep commented Aug 9, 2018

It happened because server can`t define browser language. So just changing defaultLangFunction solved problem to me.

Example:

function LocalizeLoaderFactory(translate: TranslateService, location: Location, setting: LocalizeRouterSettings, http: HttpClient) {
  setting.defaultLangFunction = (languages, cachedLang, browserLang) => {
    return languages[0] || cachedLang || browserLang;
  }
  return new LocalizeRouterHttpLoader(translate, location, setting, http, './locales.json');
}

@psmyda
Copy link

psmyda commented Aug 24, 2018

I have the same error and above solution did not resolve it.

@meeroslav meeroslav added this to the Version 1 milestone Nov 5, 2018
@psmyda
Copy link

psmyda commented Dec 10, 2018

Please refer to this link for solution ngx-translate/core#890 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants