autodetection build error
Closed this issue · 8 comments
Hi
Many thanks for creating this!
I have an issue with on CI build since v1.3 I think related to auto-detection. any ideas?
11:45:41.442 | ERR! \| let browserLang = "";
-- | --
11:45:41.442 | ERR! \| if (typeof navigator !== "undefined") {
11:45:41.442 | ERR! > browserLang = ((navigator?.languages && navigator?.languages[0]) \|\|
11:45:41.442 | ERR! \| navigator?.language)
11:45:41.442 | ERR! \| .split("-")[0]
Hi phola,
thank you for reaching out. I assume "navigator" is not available in your test environment (probably pure node nothing linke jsdom).
Can you tell me more about the tech stack for your CI build? Are you using jest / mocha ?
Cheers!
just checked and this error happens locally too when a component using this hook is included in https://storybook.js.org/ when building storybook (which uses webpack i believe) . Think you are correct maybe a simple if (typeof window === 'undefined')
check would fix?
Hi phola,
can you try the file from the issue-branch:
https://github.com/martinkr/next-export-i18n/tree/issue-15/module/dist
In case your CI setup installs all files from the package.json, please add he branch's url instead of the npm-url (https://docs.npmjs.com/cli/v8/configuring-npm/package-json#github-urls)
If everything works out, I'll push a new release, but I don't want to litter npm with "trial versions" ti fix this issue :)
Thank you :)
Cheers!
@martinkr I've overwritten the local index file from node_modules and still getting the same error. This was supposed to fix it?
@AlexStefan @martinkr Yep me too
@AlexStefan i have overwritten the getDefaultLanguage to this:
const getDefaultLanguage = (userI18n) => { let browserLang; if (navigator) { browserLang = navigator.language.split('-')[0] } if (browserLang && userI18n.translations[browserLang]) { return browserLang; } return userI18n.defaultLang; };
and now it works, i don't know why ? :D
Hey,
thank you for testing. This is exaclty what the new code from 1.3.1 is doing as well (Adjusting the check for navigator to be more robust). The issue is propably that your CI environment does not have a complete DOM.
Going to release the new code in a few minutes and going to close the issue afterwards.
Cheers1
v1.3.1