Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(css): only use files the current bundle contains #16684

Merged
merged 1 commit into from
May 28, 2024

Conversation

susnux
Copy link
Contributor

@susnux susnux commented May 15, 2024

Description

If using multiple output formats like es and cjs and running vite in watch mode, then generateBundle will be called once per output format. The bundle on each call only contains the files for the current output format, but our pureCSSChunks contain all files (from all output formats). So we need to filter the chunk list to only contain valid files, as otherwise basename will fail with:

The "path" argument must be of type string. Received undefined

Output when adding console output:
// console.warn(pureCssChunkNames)
[
  'chunks/NcMentionBubble.vue_vue_type_style_index_0_scoped_791c3b28_lang-D4yLtEdw.mjs',
  'chunks/NcRichText.vue_vue_type_style_index_0_scoped_6233f030_lang-CHHaElsZ.mjs',
  undefined,
  undefined
]
// console.warn([...pureCssChunks].map(c => c.fileName))
[
  'chunks/NcMentionBubble.vue_vue_type_style_index_0_scoped_791c3b28_lang-!~{00R}~.mjs',
  'chunks/NcRichText.vue_vue_type_style_index_0_scoped_6233f030_lang-!~{019}~.mjs',
  'chunks/NcMentionBubble.vue_vue_type_style_index_0_scoped_791c3b28_lang-!~{00R}~.cjs',
  'chunks/NcRichText.vue_vue_type_style_index_0_scoped_6233f030_lang-!~{019}~.cjs'
]
// Now the build fails with:
// [vite:css-post] The "path" argument must be of type string. Received undefined

// Here the second run for cjs is now running
// console.warn(pureCssChunkNames)
[
  undefined,
  undefined,
  'chunks/NcMentionBubble.vue_vue_type_style_index_0_scoped_791c3b28_lang-TWgAPFkJ.cjs',
  'chunks/NcRichText.vue_vue_type_style_index_0_scoped_6233f030_lang-D6wotsd_.cjs'
]
// console.warn([...pureCssChunks].map(c => c.fileName))
[
  'chunks/NcMentionBubble.vue_vue_type_style_index_0_scoped_791c3b28_lang-!~{00R}~.mjs',
  'chunks/NcRichText.vue_vue_type_style_index_0_scoped_6233f030_lang-!~{019}~.mjs',
  'chunks/NcMentionBubble.vue_vue_type_style_index_0_scoped_791c3b28_lang-!~{00R}~.cjs',
  'chunks/NcRichText.vue_vue_type_style_index_0_scoped_6233f030_lang-!~{019}~.cjs'
]

If using multiple output formats like `es` and `cjs` and running vite
in watch mode, then `generateBundle` will be called once per output format.
The bundle on each call only contains the files for the current output format,
but our `pureCSSChunks` contain all files (from all output formats).
So we need to filter the chunk list to only contain valid files,
as otherwise `basename` will fail with:

> The "path" argument must be of type string. Received undefined

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Copy link

stackblitz bot commented May 15, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

Good catch!

@bluwy bluwy merged commit 15a6ebb into vitejs:main May 28, 2024
12 checks passed
@susnux susnux deleted the fix/css-two-output-formats branch May 28, 2024 06:03
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.

None yet

2 participants