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

autodetection build error #15

Closed
phola opened this issue Jan 20, 2022 · 8 comments · Fixed by #17
Closed

autodetection build error #15

phola opened this issue Jan 20, 2022 · 8 comments · Fixed by #17
Assignees
Milestone

Comments

@phola
Copy link

phola commented Jan 20, 2022

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]
@martinkr
Copy link
Owner

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!

@martinkr martinkr self-assigned this Jan 20, 2022
@martinkr martinkr added the awaiting answer Feedback necessary to decide wether to proceed or close the issue label Jan 20, 2022
@phola
Copy link
Author

phola commented Jan 20, 2022

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?

@martinkr
Copy link
Owner

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 martinkr added this to the 1.3.1 milestone Jan 24, 2022
@AlexStefan
Copy link

@martinkr I've overwritten the local index file from node_modules and still getting the same error. This was supposed to fix it?

@XamHans
Copy link

XamHans commented Feb 1, 2022

@AlexStefan @martinkr Yep me too

@XamHans
Copy link

XamHans commented Feb 1, 2022

@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

@martinkr
Copy link
Owner

martinkr commented Feb 1, 2022

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

@martinkr martinkr removed the awaiting answer Feedback necessary to decide wether to proceed or close the issue label Feb 1, 2022
@martinkr martinkr linked a pull request Feb 1, 2022 that will close this issue
@martinkr
Copy link
Owner

martinkr commented Feb 1, 2022

v1.3.1

@martinkr martinkr closed this as completed Feb 1, 2022
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

Successfully merging a pull request may close this issue.

4 participants