vite icon indicating copy to clipboard operation
vite copied to clipboard

fix(optimizer): align relative `build.rollupOptions.input` resolution with rollup

Open sapphi-red opened this issue 7 months ago • 8 comments

Description

computeEntries resolves relative build.rollupOptions.input from the root. https://github.com/vitejs/vite/blob/61b6b96b191c6071b9c574ad4c795f97f2646f18/packages/vite/src/node/optimizer/scan.ts#L244-L265 https://github.com/vitejs/vite/blob/61b6b96b191c6071b9c574ad4c795f97f2646f18/packages/vite/src/node/server/pluginContainer.ts#L341-L344 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 https://github.com/vitejs/vite/discussions/15834#discussioncomment-13207937 refs #20079

sapphi-red avatar May 21 '25 12:05 sapphi-red

/ecosystem-ci run

patak-dev avatar May 21 '25 12:05 patak-dev

Open in StackBlitz

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

commit: 3105302

pkg-pr-new[bot] avatar May 21 '25 12:05 pkg-pr-new[bot]

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 avatar May 22 '25 02:05 sapphi-red

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 avatar May 22 '25 03:05 sapphi-red

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

sapphi-red avatar May 22 '25 03:05 sapphi-red

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 avatar May 22 '25 03:05 sapphi-red

/ecosystem-ci run

sapphi-red avatar Jun 06 '25 07:06 sapphi-red

📝 Ran ecosystem CI on 3105302: Open

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

:white_check_mark: 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

vite-ecosystem-ci[bot] avatar Jun 06 '25 08:06 vite-ecosystem-ci[bot]

vike is failing with a different error but the reason is same with https://github.com/vitejs/vite/pull/20080#issuecomment-2899825610 and not caused by this PR.

sapphi-red avatar Jun 06 '25 08:06 sapphi-red