Skip to content

Conversation

sapphi-red
Copy link
Member

Description

computeEntries resolves relative build.rollupOptions.input from the root.

const resolvePath = async (p: string) => {
const id = (
await environment.pluginContainer.resolveId(p, undefined, {
scan: true,
})
)?.id
if (id === undefined) {
throw new Error(
`failed to resolve rollupOptions.input value: ${JSON.stringify(p)}.`,
)
}
return id
}
if (typeof buildInput === 'string') {
entries = [await resolvePath(buildInput)]
} else if (Array.isArray(buildInput)) {
entries = await Promise.all(buildInput.map(resolvePath))
} else if (isObject(buildInput)) {
entries = await Promise.all(Object.values(buildInput).map(resolvePath))
} else {
throw new Error('invalid rollupOptions.input value.')
}

importer: string | undefined = join(
this.environment.config.root,
'index.html',
),

reproduction: https://stackblitz.com/edit/vitejs-vite-nte18shp?file=package.json,vite.config.js&terminal=dev

On the other hand, rollup resolves relative build.rollupOptions.input from process.cwd().

This PR fixes the computeEntries to align the behavior with rollup. I think we should align with rollup, but that would probably have a bigger impact, so I made that a separate PR.

A workaround is to call path.resolve in the config before passing to build.rollupOptions.input.

reported at #15834 (reply in thread)
refs #20079

@sapphi-red sapphi-red added has workaround p3-minor-bug An edge case that only affects very specific usage (priority) feat: deps optimizer Esbuild Dependencies Optimization labels May 21, 2025
@patak-dev
Copy link
Member

/ecosystem-ci run

Copy link

pkg-pr-new bot commented May 21, 2025

Open in StackBlitz

npm i https://pkg.pr.new/vite@20080

commit: 3105302

@vite-ecosystem-ci

This comment was marked as outdated.

@vite-ecosystem-ci
Copy link

@sapphi-red
Copy link
Member Author

Hmm, it seems vike fails on this branch and passes on latest main (https://github.com/vitejs/vite-ecosystem-ci/actions/runs/151765559389).
The error is happening in build, which is strange...

@sapphi-red
Copy link
Member Author

It seems pnpm tsx ecosystem-ci.ts vike --repo sapphi-red/vite --branch fix/optimizer-resolve-relative-build-rollupOptions-input passes, but pnpm tsx ecosystem-ci.ts vike --repo sapphi-red/vite --commit 7872cfc6181bd19fe6f42d8990a0ddfa56dbf8f8 fails.

@sapphi-red
Copy link
Member Author

It seems it passes with rollup 4.38.0 and fails with 4.39.0.

@sapphi-red
Copy link
Member Author

OK. pnpm tsx ecosystem-ci.ts vike --repo sapphi-red/vite --branch fix/optimizer-resolve-relative-build-rollupOptions-input sets overrides.rollup: '4.40.1' and pnpm tsx ecosystem-ci.ts vike --repo sapphi-red/vite --commit 7872cfc6181bd19fe6f42d8990a0ddfa56dbf8f8 sets overrides.rollup: '^4.40.0' (because it uses pkg.pr.new), and there was a bug in rollup 4.39.0 - 4.40.0. So the failure is not caused by this PR.

@sapphi-red
Copy link
Member Author

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

📝 Ran ecosystem CI on 3105302: Open

suite result latest scheduled
analogjs failure failure
histoire failure failure
astro failure failure
previewjs failure failure
vike failure failure
sveltekit failure failure
vite-plugin-cloudflare failure failure

laravel, react-router, quasar, qwik, ladle, nuxt, unocss, storybook, vite-plugin-pwa, vite-plugin-react, rakkas, vite-environment-examples, vite-setup-catalogue, vitepress, marko, vitest, vite-plugin-svelte, vuepress, waku, vite-plugin-vue

@sapphi-red
Copy link
Member Author

vike is failing with a different error but the reason is same with #20080 (comment) and not caused by this PR.

@sapphi-red sapphi-red merged commit 9759c29 into vitejs:main Jun 6, 2025
16 checks passed
@sapphi-red sapphi-red deleted the fix/optimizer-resolve-relative-build-rollupOptions-input branch June 6, 2025 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: deps optimizer Esbuild Dependencies Optimization has workaround p3-minor-bug An edge case that only affects very specific usage (priority) trigger: preview
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants