withastro / astro

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

Script cannot be detected as server or static mode on Astro v5.x #12609

Open cworld1 opened 1 day ago

cworld1 commented 1 day ago

Astro Info

$ astro info
Astro                    v5.0.1
Node                     v23.2.0
System                   Windows (x64)
Package Manager          bun
Output                   server
Adapter                  @astrojs/vercel
Integrations             @astrojs/tailwind
                         @astrojs/sitemap
                         @astrojs/mdx
                         astro-icon

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

Firefox

Describe the Bug

For file src/utils.ts

export function A() {
  // Used in dynamic astro page P
}

export function B() {
  // Used as a static typescript function in a simple component S using <script>import xxx</script>
}

but when component S inserted in dynamic server page P, astro seems cannot split out scripts and shows warnings.

Note: this method can work on Astro v4.x

The "astro:content" module is only available server-side.
Stack Trace
at generateContentEntryFile (file:///D:/code/web/astro-theme-pure/node_modules/astro/dist/content/vite-plugin-content-virtual-mod.js:197:11)
    at LoadPluginContext.load (file:///D:/code/web/astro-theme-pure/node_modules/astro/dist/content/vite-plugin-content-virtual-mod.js:93:28)
    at EnvironmentPluginContainer.load (file:///D:/code/web/astro-theme-pure/node_modules/vite/dist/node/chunks/dep-A4nAWF7x.js:46981:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async loadAndTransform (file:///D:/code/web/astro-theme-pure/node_modules/vite/dist/node/chunks/dep-A4nAWF7x.js:40782:22)
    at async viteTransformMiddleware (file:///D:/code/web/astro-theme-pure/node_modules/vite/dist/node/chunks/dep-A4nAWF7x.js:42292:24)

What's the expected result?

// src/utils.ts
export function A() {
  // Used in dynamic astro page P
}

export function B() {
  // Used as a static typescript function in a simple component S using <script>import xxx</script>
}

When component S inserted in dynamic server page P, astro can work well.

Link to Minimal Reproducible Example

I'll append if it is needed

Participation

github-actions[bot] commented 1 day ago

Hello @cworld1. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs repro will be closed if they have no activity within 3 days.