diff --git a/.changeset/eighty-laws-brake.md b/.changeset/eighty-laws-brake.md new file mode 100644 index 000000000..b4947f1aa --- /dev/null +++ b/.changeset/eighty-laws-brake.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Update `chunkFileNames` to avoid emitting invalid characters diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index 0bfb4e3ae..407e0ecde 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -172,7 +172,21 @@ async function ssrBuild( format: 'esm', // Server chunks can't go in the assets (_astro) folder // We need to keep these separate - chunkFileNames: `chunks/[name].[hash].mjs`, + chunkFileNames(chunkInfo) { + const { name } = chunkInfo; + // Sometimes chunks have the `@_@astro` suffix due to SSR logic. Remove it! + // TODO: refactor our build logic to avoid this + if (name.includes(ASTRO_PAGE_EXTENSION_POST_PATTERN)) { + const [sanitizedName] = name.split(ASTRO_PAGE_EXTENSION_POST_PATTERN); + return `chunks/${sanitizedName}_[hash].mjs` + } + // Injected routes include "pages/[name].[ext]" already. Clean those up! + if (name.startsWith('pages/')) { + const sanitizedName = name.split('.')[0]; + return `chunks/${sanitizedName}_[hash].mjs` + } + return `chunks/[name]_[hash].mjs` + }, assetFileNames: `${settings.config.build.assets}/[name].[hash][extname]`, ...viteConfig.build?.rollupOptions?.output, entryFileNames(chunkInfo) { @@ -189,7 +203,7 @@ async function ssrBuild( } else if (chunkInfo.facadeModuleId === RESOLVED_RENDERERS_MODULE_ID) { return 'renderers.mjs'; } else if (chunkInfo.facadeModuleId === RESOLVED_SSR_MANIFEST_VIRTUAL_MODULE_ID) { - return 'manifest.[hash].mjs'; + return 'manifest_[hash].mjs'; } else { return '[name].mjs'; }