segment-boneyard / locale-string

Convert locale strings to english names and back
12 stars 2 forks source link

TypeError: Cannot read property 'split' of undefined on MERN stack application startup #4

Open soonhuat opened 6 years ago

soonhuat commented 6 years ago

i have included locale-string to process my browser language and get the native language. i included this package in the App.js, so will run on start up. when i start up the application via npm start and hit the landing page, then i got this error.

my code: const localeLanguage = localeString.parse('en-gb')

is this package missing some package?

Error: TypeError: Cannot read property 'split' of undefined at Function.parse (..../node_modules/locale-string/index.js:42:25) at getBrowserIsoLanguageCode (...../client/util/languageHelper.js:26:39)

f2prateek commented 6 years ago

The split method is only used here https://github.com/segmentio/locale-string/blob/master/index.js#L47. This suggests to me that you are calling localeString.parse(undefined) and not localeString.parse('en-gb').

Maybe write a failing test case (https://github.com/segmentio/locale-string/blob/master/test.js#L40-L44) and send it as a PR? Something simple like:

    it('fails for en-GB', function(){
      var res = locale.parse('en-GB');
    });