Repository navigation
fix(css): reject CSS entrypoints when build.cssCodeSplit: false - #23112
Conversation
|
Would you provide a reproduction? or explain what the crash is and how this PR fixes it? |
a122963 to
8278690
Compare
|
@sapphi-red I've added a playground which sets up the conditions of the crash I was seeing in our downstream build, where we have an entry which is something like [plugin vite:css-post]
TypeError: Cannot read properties of undefined (reading 'referenceId')
at file:///C:/.../projects/vite/packages/vite/dist/node/chunks/node.js:22859:109
at Array.forEach (<anonymous>)
at PluginContextImpl.generateBundle (file:///C:/.../projects/vite/packages/vite/dist/node/chunks/node.js:22855:23)
at async plugin (file:///C:/.../projects/vite/node_modules/.pnpm/rolldown@1.2.0/node_modules/rolldown/dist/shared/bindingify-input-options-_ppP73I9.mjs:1707:4)
at async plugin.<computed> (file:///C:/.../projects/vite/node_modules/.pnpm/rolldown@1.2.0/node_modules/rolldown/dist/shared/bindingify-input-options-_ppP73I9.mjs:1959:12)
at aggregateBindingErrorsIntoJsError (file:///C:/.../projects/vite/node_modules/.pnpm/rolldown@1.2.0/node_modules/rolldown/dist/shared/error-DFGNOCle.mjs:48:18)
at unwrapBindingResult (file:///C:/.../projects/vite/node_modules/.pnpm/rolldown@1.2.0/node_modules/rolldown/dist/shared/error-DFGNOCle.mjs:18:128)
at #build (file:///C:/.../projects/vite/node_modules/.pnpm/rolldown@1.2.0/node_modules/rolldown/dist/shared/rolldown-build-CdF8HAHX.mjs:3276:34)
at async buildEnvironment (file:///C:/.../projects/vite/packages/vite/dist/node/chunks/node.js:33669:66)
at async Object.build (file:///C:/.../projects/vite/packages/vite/dist/node/chunks/node.js:34091:19)
at async Object.buildApp (file:///C:/.../projects/vite/packages/vite/dist/node/chunks/node.js:34088:153)
at async CAC.<anonymous> (file:///C:/.../projects/vite/packages/vite/dist/node/cli.js:776:3) {
errors: [Getter/Setter]
}This fixes it by ensuring that |
| // `.pcss` avoids a separate built-in validation that rejects literal `.css` entries when `cssCodeSplit` is `false`. | ||
| fileURLToPath(new URL('./style-only.pcss', import.meta.url)), |
There was a problem hiding this comment.
As the error for .css describes, it's not expected to pass CSS files (including files generating.pcss) as an entrypoint when build.cssCodeSplit is set to false.
Instead of this configuration, if you add import './style-only.pcss' in index.js, you'll get the same behavior. What is the reason you are using this configuration?
There was a problem hiding this comment.
I think the main reason for it is that it's been that way for some time. We're building a component library with a separate CSS export, but we're not exporting our html. It's a little counter-intuitive that setting up the import in your html would be how you're expected to generate CSS package exports. I do have a couple of questions on that:
- Will the CSS imported via html still be caught and generated in lib mode?
- These changes treat the addition to
cssEntriesMapa bit more consistently throughout thecssPostPlugincode. Is there value in having that consistency even if the originating cause is because of misconfiguration?
There was a problem hiding this comment.
- Will the CSS imported via html still be caught and generated in lib mode?
It will only be included if you specify the HTML as an entrypoint. But I don't think that's the case. You need to import it so it's part of the module graph (i.e. reachable from the entrypoint).
- These changes treat the addition to
cssEntriesMapa bit more consistently throughout thecssPostPlugincode. Is there value in having that consistency even if the originating cause is because of misconfiguration?
If the code is simpler, I think we can merge it. But I'm not sure about the consistency for a unsupported functionality.
There was a problem hiding this comment.
If the code is simpler, I think we can merge it. But I'm not sure about the consistency for a unsupported functionality.
I don't know if I would say it's simpler, necessarily. It guarantees expectations about cssEntriesMap in later logic, and consolidates emitting an entry file with populating that map. So in this small way it's a little bit easier to reason about. In terms of complexity vs simplicity, it adds some redirection and a little bit more cognitive overhead when reading the code, so it's slightly more complex that way.
I'm not sure about the consistency for a unsupported functionality.
I'm also a bit stuck on this. It does make scss (and pcss) defined as their own entries work, but if that is an anti-pattern as far as vite is concerned, it seems like the early error condition should interrupt for those as well as regular css entries. I'm very new to the internal vite domain, but is there a way it could throw the error if the expected output for the entry is CSS rather than just checking the file extension?
There was a problem hiding this comment.
is there a way it could throw the error if the expected output for the entry is CSS rather than just checking the file extension?
It's a bit tricky. I think for now changing this if to use CSS_LANGS_RE would be better.
vite/packages/vite/src/node/build.ts
Line 640 in ef02435
There was a problem hiding this comment.
I have made that update. I'm still not sure if you would like to keep the changes in css.ts. They do make some things somewhat "safer" than they were previously, but the issues those changes were intended to address can't be reproduced with the change to build.ts, and the changes aren't absolutely necessary.
The one thing I'm not sure about is if the manifest ends up with the correct CSS info in the final fall-through case without these changes. I think these changes ensure that because the emitted CSS gets added to cssEntriesMap. This is a case I'm not certain how to replicate and test, but if it is solving for that, it would be in this code (css.ts lines 1096-1121)
a3034c5 to
1c675f7
Compare
1c675f7 to
e830035
Compare
e830035 to
6d44039
Compare
6d44039 to
1ab085e
Compare
|
@sapphi-red with regard to this comment, I did some research and found that the effect on the manifest was not more correct than it was previously, so I've removed the majority of the changes from The changes left in there are one ensuring that CSS entries created by plugins fail in the same way as those provided to If that's not desired, it's really easy to pull out, as it sits in its own commit, which I can remove if needed. |
…es, as with split mode" This reverts commit d9701f6.
build.cssCodeSplit: false
sapphi-red
left a comment
There was a problem hiding this comment.
Thanks!
The changes left in there are one ensuring that CSS entries created by plugins fail in the same way as those provided to
entrydirectly, and a change accounting for empty CSS files when not in split mode. In split mode, a file is emitted for these chunks, so this change aligns the two modes in terms of their output. (A CSS file is emitted in both cases.)
I've reverted this change. I think it is fine to remove the CSS file as long as it's not an entrypoint. I'll follow up with this one in a separate PR
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [vite](https://vite.dev) ([source](https://github.com/vitejs/vite/tree/HEAD/packages/vite)) | [`8.3.7` → `8.3.8`](https://renovatebot.com/diffs/npm/vite/8.3.7/8.3.8) |  |  | --- ### Release Notes <details> <summary>vitejs/vite (vite)</summary> ### [`v8.3.8`](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-838-2026-11-11-small) [Compare Source](vitejs/vite@v8.3.7...v8.3.8) ##### Bug Fixes - **build:** keep `magicString` and `ast` in transform hook meta ([#​24012](vitejs/vite#24012)) ([a3b28e8](vitejs/vite@a3b28e8)) - **bundled-dev:** emit assets referenced by inline workers during load ([#​23103](vitejs/vite#23103)) ([5e50bae](vitejs/vite@5e50bae)) - **config:** skip native loader compat checks for type-only imports ([#​24021](vitejs/vite#24021)) ([e554294](vitejs/vite@e554294)) - **css:** reject CSS entrypoints when `build.cssCodeSplit: false` ([#​23112](vitejs/vite#23112)) ([e4ad62b](vitejs/vite@e4ad62b)) - **deps:** update all non-major dependencies ([#​24027](vitejs/vite#24027)) ([a13aa04](vitejs/vite@a13aa04)) - hide console window when running `yarn config get` on Windows ([#​24013](vitejs/vite#24013)) ([3f6c4cd](vitejs/vite@3f6c4cd)) ##### Performance Improvements - **css:** import sass once instead of per file ([#​24041](vitejs/vite#24041)) ([db8b119](vitejs/vite@db8b119)) - defer `net use` until a UNC path is resolved on Windows ([#​24014](vitejs/vite#24014)) ([b643046](vitejs/vite@b643046)) ##### Miscellaneous Chores - **deps:** update dependency [@​types/node](https://github.com/types/node) to v26 ([#​24029](vitejs/vite#24029)) ([dd780cd](vitejs/vite@dd780cd)) - enable vitest plugin in Oxlint ([#​24052](vitejs/vite#24052)) ([ce979e4](vitejs/vite@ce979e4)) - enable vitest style rules in Oxlint ([#​24053](vitejs/vite#24053)) ([b8c8270](vitejs/vite@b8c8270)) - revert "fix(build): keep `magicString` and `ast` in transform hook meta ([#​24012](vitejs/vite#24012))" ([#​24065](vitejs/vite#24065)) ([afc44f0](vitejs/vite@afc44f0)) ##### Code Refactoring - **optimizer:** use non-capturing group for external types regex ([#​24048](vitejs/vite#24048)) ([ef23433](vitejs/vite@ef23433)) ##### Tests - avoid joining logs for assertion ([#​24057](vitejs/vite#24057)) ([fbb0a4e](vitejs/vite@fbb0a4e)) </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4yMzkuMSIsInVwZGF0ZWRJblZlciI6IjQ0LjIzOS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [vite](https://vite.dev) ([source](https://github.com/vitejs/vite/tree/HEAD/packages/vite)) | [`8.3.7` → `8.3.8`](https://renovatebot.com/diffs/npm/vite/8.3.7/8.3.8) |  |  | --- ### Release Notes <details> <summary>vitejs/vite (vite)</summary> ### [`v8.3.8`](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-838-2026-11-11-small) [Compare Source](vitejs/vite@v8.3.7...v8.3.8) ##### Bug Fixes - **build:** keep `magicString` and `ast` in transform hook meta ([#​24012](vitejs/vite#24012)) ([a3b28e8](vitejs/vite@a3b28e8)) - **bundled-dev:** emit assets referenced by inline workers during load ([#​23103](vitejs/vite#23103)) ([5e50bae](vitejs/vite@5e50bae)) - **config:** skip native loader compat checks for type-only imports ([#​24021](vitejs/vite#24021)) ([e554294](vitejs/vite@e554294)) - **css:** reject CSS entrypoints when `build.cssCodeSplit: false` ([#​23112](vitejs/vite#23112)) ([e4ad62b](vitejs/vite@e4ad62b)) - **deps:** update all non-major dependencies ([#​24027](vitejs/vite#24027)) ([a13aa04](vitejs/vite@a13aa04)) - hide console window when running `yarn config get` on Windows ([#​24013](vitejs/vite#24013)) ([3f6c4cd](vitejs/vite@3f6c4cd)) ##### Performance Improvements - **css:** import sass once instead of per file ([#​24041](vitejs/vite#24041)) ([db8b119](vitejs/vite@db8b119)) - defer `net use` until a UNC path is resolved on Windows ([#​24014](vitejs/vite#24014)) ([b643046](vitejs/vite@b643046)) ##### Miscellaneous Chores - **deps:** update dependency [@​types/node](https://github.com/types/node) to v26 ([#​24029](vitejs/vite#24029)) ([dd780cd](vitejs/vite@dd780cd)) - enable vitest plugin in Oxlint ([#​24052](vitejs/vite#24052)) ([ce979e4](vitejs/vite@ce979e4)) - enable vitest style rules in Oxlint ([#​24053](vitejs/vite#24053)) ([b8c8270](vitejs/vite@b8c8270)) - revert "fix(build): keep `magicString` and `ast` in transform hook meta ([#​24012](vitejs/vite#24012))" ([#​24065](vitejs/vite#24065)) ([afc44f0](vitejs/vite@afc44f0)) ##### Code Refactoring - **optimizer:** use non-capturing group for external types regex ([#​24048](vitejs/vite#24048)) ([ef23433](vitejs/vite@ef23433)) ##### Tests - avoid joining logs for assertion ([#​24057](vitejs/vite#24057)) ([fbb0a4e](vitejs/vite@fbb0a4e)) </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - "before 9am on tuesday" - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4yMjcuNCIsInVwZGF0ZWRJblZlciI6IjQ0LjIyNy40IiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZSJdfQ==--> Reviewed-on: https://code.futo.org/harbor/harbor/pulls/2346
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [vite](https://vite.dev) ([source](https://github.com/vitejs/vite/tree/HEAD/packages/vite)) | [`8.3.6` → `8.3.8`](https://renovatebot.com/diffs/npm/vite/8.3.6/8.3.8) |  |  | --- ### Release Notes <details> <summary>vitejs/vite (vite)</summary> ### [`v8.3.8`](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-838-2026-11-11-small) [Compare Source](vitejs/vite@v8.3.7...v8.3.8) ##### Bug Fixes - **build:** keep `magicString` and `ast` in transform hook meta ([#​24012](vitejs/vite#24012)) ([a3b28e8](vitejs/vite@a3b28e8)) - **bundled-dev:** emit assets referenced by inline workers during load ([#​23103](vitejs/vite#23103)) ([5e50bae](vitejs/vite@5e50bae)) - **config:** skip native loader compat checks for type-only imports ([#​24021](vitejs/vite#24021)) ([e554294](vitejs/vite@e554294)) - **css:** reject CSS entrypoints when `build.cssCodeSplit: false` ([#​23112](vitejs/vite#23112)) ([e4ad62b](vitejs/vite@e4ad62b)) - **deps:** update all non-major dependencies ([#​24027](vitejs/vite#24027)) ([a13aa04](vitejs/vite@a13aa04)) - hide console window when running `yarn config get` on Windows ([#​24013](vitejs/vite#24013)) ([3f6c4cd](vitejs/vite@3f6c4cd)) ##### Performance Improvements - **css:** import sass once instead of per file ([#​24041](vitejs/vite#24041)) ([db8b119](vitejs/vite@db8b119)) - defer `net use` until a UNC path is resolved on Windows ([#​24014](vitejs/vite#24014)) ([b643046](vitejs/vite@b643046)) ##### Miscellaneous Chores - **deps:** update dependency [@​types/node](https://github.com/types/node) to v26 ([#​24029](vitejs/vite#24029)) ([dd780cd](vitejs/vite@dd780cd)) - enable vitest plugin in Oxlint ([#​24052](vitejs/vite#24052)) ([ce979e4](vitejs/vite@ce979e4)) - enable vitest style rules in Oxlint ([#​24053](vitejs/vite#24053)) ([b8c8270](vitejs/vite@b8c8270)) - revert "fix(build): keep `magicString` and `ast` in transform hook meta ([#​24012](vitejs/vite#24012))" ([#​24065](vitejs/vite#24065)) ([afc44f0](vitejs/vite@afc44f0)) ##### Code Refactoring - **optimizer:** use non-capturing group for external types regex ([#​24048](vitejs/vite#24048)) ([ef23433](vitejs/vite@ef23433)) ##### Tests - avoid joining logs for assertion ([#​24057](vitejs/vite#24057)) ([fbb0a4e](vitejs/vite@fbb0a4e)) ### [`v8.3.7`](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-837-2026-11-09-small) [Compare Source](vitejs/vite@v8.3.6...v8.3.7) ##### Bug Fixes - **deps:** update Rolldown to v1.2.18 ([#​24038](vitejs/vite#24038)) ([517affb](vitejs/vite@517affb)) ##### Miscellaneous Chores - enable more lint rules ([#​24035](vitejs/vite#24035)) ([72f86e5](vitejs/vite@72f86e5)) ##### Tests - use `onTestFinished` for tear downs ([#​24003](vitejs/vite#24003)) ([a579e35](vitejs/vite@a579e35)) ##### Build System - generate sourcemaps in shim-deps plugin ([#​24023](vitejs/vite#24023)) ([c02138c](vitejs/vite@c02138c)) </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4yMzUuMSIsInVwZGF0ZWRJblZlciI6IjQ0LjIzOS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
This avoids a crash when there are css-only entries in a non-splitting build.
Existing tests cover the main use-cases. I think those are enough, but if desired, I can add a new playground to cover the above case.