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: throw missing name error only when 'umd' or 'iife' are used #9886

Merged
merged 1 commit into from
Nov 8, 2022

Conversation

davidmyersdev
Copy link
Contributor

@davidmyersdev davidmyersdev commented Aug 28, 2022

Description

When build.rollupOptions.output is an array, Vite throws the following error if you don't specify build.lib.name even when umd and iife formats are not present. This is because the default for build.lib.formats is ['es', 'umd'], and the code does not currently take the build.rollupOptions.output value into account until after the error-throwing check is run.

Option "build.lib.name" is required when output formats include "umd" or "iife".

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@sapphi-red sapphi-red changed the title fix: Throw missing name error only when 'umd' or 'iife' are used fix: throw missing name error only when 'umd' or 'iife' are used Sep 1, 2022
@sapphi-red sapphi-red added p2-nice-to-have Not breaking anything but nice to have (priority) feat: library mode labels Sep 1, 2022
Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!
I have some nitpicks but it mostly looks good to me.

packages/vite/src/node/__tests__/build.spec.ts Outdated Show resolved Hide resolved
packages/vite/src/node/build.ts Outdated Show resolved Hide resolved
Comment on lines 676 to 826
outputs.forEach((output) => {
if (['umd', 'iife'].includes(output.format!) && !output.name) {
throw new Error(
'Entries in "build.rollupOptions.output" must specify "name" when output formats include "umd" or "iife".'
)
}
})
Copy link
Member

Choose a reason for hiding this comment

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

Rollup does output the following error during build. But I think it's good to have this, because this will output the error before build.

vite v3.1.0-beta.0 building for production...
✓ 1 modules transformed.
dist/index.html                   0.76 KiB
dist/my-lib-custom-filename.mjs   0.59 KiB / gzip: 0.36 KiB
You must supply "output.name" for UMD bundles that have exports so that the exports are accessible in environments without a module loader.

@davidmyersdev
Copy link
Contributor Author

Thanks for the feedback, @sapphi-red! I made the updates you requested.

sapphi-red
sapphi-red previously approved these changes Sep 3, 2022
@davidmyersdev
Copy link
Contributor Author

Do you want me to resolve these conflicts, or will this likely be waiting a while longer before being merged?

@sapphi-red
Copy link
Member

Sorry for taking time. It would be great if you could resolve the conflict.

@davidmyersdev
Copy link
Contributor Author

Not a problem. I'll get those resolved soon.

Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

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

Thanks for resolving the conflict!

@patak-dev patak-dev merged commit b8aa825 into vitejs:main Nov 8, 2022
@davidmyersdev davidmyersdev deleted the fix-formats-name-warning branch November 8, 2022 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: library mode p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants