From 9f781b1235556724fd87734d6dea899e19afa0cf Mon Sep 17 00:00:00 2001 From: astrobot-houston Date: Fri, 3 Jul 2026 08:00:03 +0000 Subject: [PATCH 1/2] fix(config-alias): skip data URIs in CSS url() alias resolution Data URIs like url('data:image/svg+xml;base64,...') were incorrectly matched by the baseUrl alias regex and passed to fs.statSync(), which throws ENAMETOOLONG when the base64 string exceeds the OS filename length limit (255 bytes). Add an early return in replaceAliases() to skip data: URIs since they are inline content, not file paths to resolve. Fixes #17293 --- .../src/vite-plugin-config-alias/index.ts | 2 ++ .../astro/test/alias-css-url-data-uri.test.ts | 28 +++++++++++++++++++ .../alias-css-url-data-uri/astro.config.mjs | 2 ++ .../alias-css-url-data-uri/package.json | 3 ++ .../src/pages/index.astro | 11 ++++++++ .../alias-css-url-data-uri/tsconfig.json | 5 ++++ 6 files changed, 51 insertions(+) create mode 100644 packages/astro/test/alias-css-url-data-uri.test.ts create mode 100644 packages/astro/test/fixtures/alias-css-url-data-uri/astro.config.mjs create mode 100644 packages/astro/test/fixtures/alias-css-url-data-uri/package.json create mode 100644 packages/astro/test/fixtures/alias-css-url-data-uri/src/pages/index.astro create mode 100644 packages/astro/test/fixtures/alias-css-url-data-uri/tsconfig.json diff --git a/packages/astro/src/vite-plugin-config-alias/index.ts b/packages/astro/src/vite-plugin-config-alias/index.ts index bd7a8e367102..f60da1e7ade0 100644 --- a/packages/astro/src/vite-plugin-config-alias/index.ts +++ b/packages/astro/src/vite-plugin-config-alias/index.ts @@ -142,6 +142,8 @@ export default function configAliasVitePlugin({ const replaceAliases = (match: string, importId: string) => { if (!importId) return match; + // Skip data URIs — they are inline content, not file paths. + if (importId.startsWith('data:')) return match; const resolved = resolveWithAlias(importId, configAlias); if (resolved) { diff --git a/packages/astro/test/alias-css-url-data-uri.test.ts b/packages/astro/test/alias-css-url-data-uri.test.ts new file mode 100644 index 000000000000..4d2c07f78abb --- /dev/null +++ b/packages/astro/test/alias-css-url-data-uri.test.ts @@ -0,0 +1,28 @@ +import assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; +import { type Fixture, loadFixture } from './test-utils.ts'; + +// Regression test for https://github.com/withastro/astro/issues/17293 +// CSS url() with data URIs should not crash when tsconfig baseUrl is set. +describe('CSS url() with data URIs and tsconfig baseUrl', () => { + let fixture: Fixture; + + before(async () => { + fixture = await loadFixture({ + root: './fixtures/alias-css-url-data-uri/', + }); + await fixture.build(); + }); + + it('preserves data URIs in url() without ENAMETOOLONG crash', async () => { + const html = await fixture.readFile('/index.html'); + const $ = cheerio.load(html); + + const styleTag = $('style').html() || ''; + assert.ok( + styleTag.includes('data:image/svg+xml;base64,'), + 'CSS should preserve the data URI', + ); + }); +}); diff --git a/packages/astro/test/fixtures/alias-css-url-data-uri/astro.config.mjs b/packages/astro/test/fixtures/alias-css-url-data-uri/astro.config.mjs new file mode 100644 index 000000000000..d7ac4b718a29 --- /dev/null +++ b/packages/astro/test/fixtures/alias-css-url-data-uri/astro.config.mjs @@ -0,0 +1,2 @@ +import { defineConfig } from 'astro/config'; +export default defineConfig({}); diff --git a/packages/astro/test/fixtures/alias-css-url-data-uri/package.json b/packages/astro/test/fixtures/alias-css-url-data-uri/package.json new file mode 100644 index 000000000000..d3325f2cb1be --- /dev/null +++ b/packages/astro/test/fixtures/alias-css-url-data-uri/package.json @@ -0,0 +1,3 @@ +{ + "name": "@test/alias-css-url-data-uri" +} diff --git a/packages/astro/test/fixtures/alias-css-url-data-uri/src/pages/index.astro b/packages/astro/test/fixtures/alias-css-url-data-uri/src/pages/index.astro new file mode 100644 index 000000000000..101354a69734 --- /dev/null +++ b/packages/astro/test/fixtures/alias-css-url-data-uri/src/pages/index.astro @@ -0,0 +1,11 @@ +--- + +--- + +

Hello

+ + diff --git a/packages/astro/test/fixtures/alias-css-url-data-uri/tsconfig.json b/packages/astro/test/fixtures/alias-css-url-data-uri/tsconfig.json new file mode 100644 index 000000000000..fb8ee3df7116 --- /dev/null +++ b/packages/astro/test/fixtures/alias-css-url-data-uri/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "baseUrl": "." + } +} From ee57c578c640a0cffba3f510dc80fa7f425371cf Mon Sep 17 00:00:00 2001 From: astrobot-houston Date: Fri, 3 Jul 2026 08:00:07 +0000 Subject: [PATCH 2/2] fix(config-alias): skip data URIs in CSS url() alias resolution Data URIs like url('data:image/svg+xml;base64,...') were incorrectly matched by the baseUrl alias regex and passed to fs.statSync(), which throws ENAMETOOLONG when the base64 string exceeds the OS filename length limit (255 bytes). Add an early return in replaceAliases() to skip data: URIs since they are inline content, not file paths to resolve. Fixes #17293 --- pnpm-lock.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 866ff8491b60..bdd27e8ee8e7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1917,6 +1917,8 @@ importers: specifier: workspace:* version: link:../../.. + packages/astro/test/fixtures/alias-css-url-data-uri: {} + packages/astro/test/fixtures/alias-path-alias-style: dependencies: astro: