Skip to content

[v6] Virtual modules throw error when used on client #15919

@twocaretcat

Description

@twocaretcat

Astro Info

Astro                    v6.0.4
Vite                     v7.3.1
Node                     v22.20.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

In Astro 5, I had a client-side script in a page that imported the virtual astro:i18n module like so:

<script>
import { getRelativeLocaleUrl } from 'astro:i18n';

// ...
</script>

I'm not sure if you're necessarily supposed to import this client-side, but it worked up till 5.18.1. It stopped working in 6.0.0-alpha.1, failing with the following error on build:

16:09:20 [vite] Re-optimizing dependencies because vite config has changed
16:09:20 [types] Generated 115ms
16:09:20 [build] output: "static"
16:09:20 [build] mode: "static"
16:09:20 [build] directory: /home/j/Desktop/Astro Repro 2/dist/
16:09:20 [build] Collecting build info...
16:09:20 [build] ✓ Completed in 132ms.
16:09:20 [build] Building static entrypoints...
16:09:21 [WARN] [vite] "matchHostname", "matchPathname", "matchPort" and "matchProtocol" are imported from external module "@astrojs/internal-helpers/remote" but never used in "node_modules/astro/dist/assets/utils/index.js".
16:09:21 [vite] ✓ built in 884ms
16:09:21 [ERROR] [vite] ✗ Build failed in 25ms
[ServerOnlyModule] [astro-manifest-plugin] Could not load astro:config/server (imported by node_modules/astro/dist/virtual-modules/i18n.js): The "astro:config/server" module is only available server-side.
  Error reference:
    https://docs.astro.build/en/reference/errors/server-only-module/
  Stack trace:
    at Object.handler (file:///home/j/Desktop/Astro%20Repro%202/node_modules/astro/dist/manifest/virtual-module.js:67:19)
    at file:///home/j/Desktop/Astro%20Repro%202/node_modules/rollup/dist/es/shared/node-entry.js:22571:40
    at async file:///home/j/Desktop/Astro%20Repro%202/node_modules/rollup/dist/es/shared/node-entry.js:21445:33
npm verbose cwd /home/j/Desktop/Astro Repro 2
npm verbose os Linux 5.15.0-171-generic
npm verbose node v22.20.0
npm verbose npm  v11.11.0
npm verbose exit 1
npm verbose code 1

It looks like this issue was caused by changes to manifest/virtual-module.ts and virtual-modules/i18n.ts
between 5.18.1 and 6.0.0-alpha.1
.

I imagine one can workaround this by using this module server-side instead and passing whatever result to the client via data attributes.

What's the expected result?

I can import and use virtual modules like astro:i18n on the client without errors.

Link to Minimal Reproducible Example

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

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: astroRelated to the core `astro` package (scope)

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions