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

Failed to get locale informations #1961

Closed
1 task
torn4dom4n opened this issue Jun 5, 2024 · 13 comments · Fixed by #1987 or #2167
Closed
1 task

Failed to get locale informations #1961

torn4dom4n opened this issue Jun 5, 2024 · 13 comments · Fixed by #1987 or #2167

Comments

@torn4dom4n
Copy link
Contributor

What version of starlight are you using?

0.24.0

What version of astro are you using?

4.9.3

What package manager are you using?

bun

What operating system are you using?

Windows

What browser are you using?

Chrome

Describe the Bug

I get this bug after updating Starlight to v0.24.0

1:58:17 AM [vite] Error when evaluating SSR module /node_modules/@astrojs/starlight/utils/i18n.ts:
|- AstroUserError: Failed to get locale informations for the 'en' locale.
    at new AstroUserError (C:\Users\Windows\Documents\GitHub\AREA44\playastro\node_modules\astro\dist\core\errors\errors.js:96:9)
    at getLocaleInfo (:99:47)
    at <anonymous> (:5:48)
    at processTicksAndRejections (:12:39)

1:58:17 AM [vite] Error when evaluating SSR module /node_modules/@astrojs/starlight/integrations/shared/localeToLang.ts: failed to import "/node_modules/@astrojs/starlight/utils/i18n.ts"
|- AstroUserError: Failed to get locale informations for the 'en' locale.
    at new AstroUserError (C:\Users\Windows\Documents\GitHub\AREA44\playastro\node_modules\astro\dist\core\errors\errors.js:96:9)
    at getLocaleInfo (:99:47)
    at <anonymous> (:5:48)
    at processTicksAndRejections (:12:39)

1:58:17 AM [vite] Error when evaluating SSR module /node_modules/@astrojs/starlight/integrations/expressive-code/translations.ts: failed to import "/node_modules/@astrojs/starlight/integrations/shared/localeToLang.ts"
|- AstroUserError: Failed to get locale informations for the 'en' locale.
    at new AstroUserError (C:\Users\Windows\Documents\GitHub\AREA44\playastro\node_modules\astro\dist\core\errors\errors.js:96:9)
    at getLocaleInfo (:99:47)
    at <anonymous> (:5:48)
    at processTicksAndRejections (:12:39)

1:58:17 AM [vite] Error when evaluating SSR module /node_modules/@astrojs/starlight/integrations/expressive-code/index.ts: failed to import "/node_modules/@astrojs/starlight/integrations/expressive-code/translations.ts"
|- AstroUserError: Failed to get locale informations for the 'en' locale.
    at new AstroUserError (C:\Users\Windows\Documents\GitHub\AREA44\playastro\node_modules\astro\dist\core\errors\errors.js:96:9)
    at getLocaleInfo (:99:47)
    at <anonymous> (:5:48)
    at processTicksAndRejections (:12:39)

1:58:17 AM [vite] Error when evaluating SSR module /node_modules/@astrojs/starlight/index.ts: failed to import "/node_modules/@astrojs/starlight/integrations/expressive-code/index.ts"
|- AstroUserError: Failed to get locale informations for the 'en' locale.
    at new AstroUserError (C:\Users\Windows\Documents\GitHub\AREA44\playastro\node_modules\astro\dist\core\errors\errors.js:96:9)
    at getLocaleInfo (:99:47)
    at <anonymous> (:5:48)
    at processTicksAndRejections (:12:39)

1:58:17 AM [vite] Error when evaluating SSR module C:\Users\Windows\Documents\GitHub\AREA44\playastro\astro.config.ts: failed to import "/node_modules/@astrojs/starlight/index.ts"
|- AstroUserError: Failed to get locale informations for the 'en' locale.
    at new AstroUserError (C:\Users\Windows\Documents\GitHub\AREA44\playastro\node_modules\astro\dist\core\errors\errors.js:96:9)
    at getLocaleInfo (:99:47)
    at <anonymous> (:5:48)
    at processTicksAndRejections (:12:39)

[astro] Unable to load your Astro config

[AstroUserError] Failed to get locale informations for the 'en' locale.
  Hint:
    Make sure to provide a valid BCP-47 tags (e.g. en, ar, or zh-CN).
  Stack trace:
    at new AstroUserError (C:\Users\Windows\Documents\GitHub\AREA44\playastro\node_modules\astro\dist\core\errors\errors.js:96:9)
    at <anonymous> (:5:48)
error: script "dev" exited with code 1

Link to Minimal Reproducible Example

https://github.com/AREA44/playastro/tree/bump-starlight

Participation

  • I am willing to submit a pull request for this issue.
@HiDeoo
Copy link
Member

HiDeoo commented Jun 5, 2024

Thanks for your report.

Just tested to run the dev and prod version of the linked repo/branch with no issues on my end. I also tried on Windows and got the same result.

Would you be able to specify your Node.js version? You should be able to get that by running bun run astro info.

@HiDeoo
Copy link
Member

HiDeoo commented Jun 5, 2024

Additional thought: could it be related to Bun or Bun version? I used bun run dev and bun run build to test your project and getTextInfo() (which I think is the most recent Intl API we are using) was something added to Node.js in version 18 so maybe it's something related to that? What's strange is that it worked for me (I tested on bun 1.1.10 on macOS and 1.1.12 on Windows).

@HiDeoo
Copy link
Member

HiDeoo commented Jun 5, 2024

I finally managed to reproduce the issue, looks like there is a --bun flag to prevent Bun from respecting script shebangs and force it to run with Bun instead of Node.js.

When using that flag, I can reproduce the issue. Is this your use case?

If yes, as it's a Bun related issue (I'm assuming some parts of the Intl API are not supported on their end), I think the best call would be to open an Issue on GitHub with Bun directly and in the meantime avoid using that flag until that API is available in Bun.

@torn4dom4n
Copy link
Contributor Author

I finally managed to reproduce the issue, looks like there is a --bun flag to prevent Bun from respecting script shebangs and force it to run with Bun instead of Node.js.

When using that flag, I can reproduce the issue. Is this your use case?

If yes, as it's a Bun related issue (I'm assuming some parts of the Intl API are not supported on their end), I think the best call would be to open an Issue on GitHub with Bun directly and in the meantime avoid using that flag until that API is available in Bun.

Thanks for your help. This issue may be associated with Bun or Node.js. I will close this now. Thank you again.

@Jarred-Sumner
Copy link

@HiDeoo the textInfo property in Intl.Locale is deprecated and only V8 implements it:

From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo:

Note: In some versions of some browsers, this method was implemented as an accessor property called textInfo. However, because it returns a new object on each access, it is now implemented as a method to prevent the situation of locale.textInfo === locale.textInfo returning false. Check the browser compatibility table for details.

@HiDeoo
Copy link
Member

HiDeoo commented Jun 9, 2024

@HiDeoo the textInfo property in Intl.Locale is deprecated and only V8 implements it:

Thanks a lot for reminding me of this, super appreciated! I totally forgot about this after a while after working on the feature. Sorry for my mistake, I just opened #1987 which should fix this issue. Thanks again.

@delucis
Copy link
Member

delucis commented Jun 9, 2024

Fixed and released in Starlight v0.24.1 🚀

Thank you to everyone reporting and helping to fix!

@aleclarson
Copy link

aleclarson commented Aug 5, 2024

@delucis
Copy link
Member

delucis commented Aug 6, 2024

Thanks for the report @aleclarson, I can confirm I’m also seeing that. Firefox doesn’t support the getTextInfo() API we’re using, but in theory our code should handle this case 🤔

Update:
Played around a bit in StackBlitz but couldn’t immediately understand what’s going wrong. The underlying error I get logged is Object.getOwnPropertyDescriptor(...) is undefined which… seems weird

Tip for anyone else wanting to debug, you can run open node_modules/@astrojs/starlight/utils/i18n.ts in the StackBlitz terminal to play with the Starlight code and see if you can get it working.

@HiDeoo
Copy link
Member

HiDeoo commented Aug 6, 2024

but in theory our code should handle this case 🤔

@delucis If you move the definition of wellKnownRTL 2 line up, above the one for BuiltInDefaultLocale, does it fix the error for you?

@delucis
Copy link
Member

delucis commented Aug 6, 2024

Let me try, it’s definitely this line that errors:

return wellKnownRTL.includes(locale.language) ? 'rtl' : 'ltr';

@delucis
Copy link
Member

delucis commented Aug 6, 2024

@delucis If you move the definition of wellKnownRTL 2 line up, above the one for BuiltInDefaultLocale, does it fix the error for you?

Ohhhhhhh. Yes! Makes sense. I’d totally missed that that was calling getLocaleInfo() before the well-known locales were defined.

@delucis
Copy link
Member

delucis commented Aug 6, 2024

PR to fix this: #2167

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