withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.43k stars 2.46k forks source link

Using virtual module astro:i18n in client side scripts causes __ASTRO_INTERNAL_I18N_CONFIG__ is not defined error #10517

Open dallyh opened 7 months ago

dallyh commented 7 months ago

Astro Info

Astro                    v4.5.8
Node                     v18.18.0
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

When virtual module astro:i18n is used in client side script, for example to get a relative locale URL with getRelativeLocaleUrl, an error is logged to the console, thus preventing the use of the module. This only happens in a dev server, build is fine.

Uncaught ReferenceError: __ASTRO_INTERNAL_I18N_CONFIG__ is not defined at i18n.js?v=d5a38680:4:56

image

What's the expected result?

Virtual module astro:i18n should be usable in client scripts while running a dev server.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-kuyvpf?file=src%2Fpages%2Findex.astro

Participation

Because789 commented 7 months ago

Could this be related to https://github.com/withastro/astro/issues/10558?

dallyh commented 6 months ago

Probably yes, the warning is also in the console:

image

ematipico commented 6 months ago

@bluwy do you have any idea why the define API doesn't create the global object in window?

https://github.com/withastro/astro/blob/6599b93f0d80547eaada84b15cbd67dd9fcd0783/packages/astro/src/i18n/vite-plugin-i18n.ts#L41-L45