Skip to content

Normalize Vite rollup input paths on Windows - #2398

Merged
webpro merged 1 commit into
webpro-nl:mainfrom
erezcor:fix-vite-html-input-windows-paths
Nov 16, 2026
Merged

webpro merged 1 commit into
webpro-nl:mainfrom
erezcor:fix-vite-html-input-windows-paths

Conversation

@erezcor

@erezcor erezcor commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

On Windows, an absolute HTML path in build.rollupOptions.input has backslashes, as with resolve(import.meta.dirname, 'nested/index.html') from Vite's multi-page docs, or fileURLToPath(new URL('pages/settings.html', import.meta.url)). getHtmlScriptEntries then takes its posix dirname, which is ., so the page's <script type="module" src="./settings.ts"> resolves against the wrong directory and is reported as an unused file.

This runs each input through toPosix before resolving it, like publicDir a few lines up.

The vite-mpa fixture gets an absolute input next to its relative ones. Without the change its test fails on Windows with pages/settings.ts as an unused file.

An absolute HTML input such as fileURLToPath(new URL('page.html', import.meta.url))
has backslashes on Windows, so the posix dirname of the HTML file became '.' and
its module scripts resolved against the wrong directory, reporting them unused.

Co-Authored-By: Claude <noreply@anthropic.com>

@webpro webpro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @erezcor! Normalizing the input here keeps nested HTML script entries relative to the right directory on Windows.

@webpro
webpro merged commit 50595ae into webpro-nl:main Nov 16, 2026
@webpro

webpro commented Nov 18, 2026

Copy link
Copy Markdown
Member

πŸš€ This pull request is included in v6.46.0. See Release 6.46.0 for release notes.

Using Knip in a commercial project? Please consider becoming a sponsor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants