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(browser): don't exclude node builtins from optimization #5082

Merged

Conversation

sheremet-va
Copy link
Member

@sheremet-va sheremet-va commented Jan 30, 2024

Description

Fixes #4535
Fixes #4892

Possibly fixes #5046

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Jan 30, 2024

Deploy Preview for fastidious-cascaron-4ded94 canceled.

Name Link
🔨 Latest commit 1f3f01c
🔍 Latest deploy log https://app.netlify.com/sites/fastidious-cascaron-4ded94/deploys/65b96bceb963010008fef51e

@@ -81,6 +81,13 @@ export default (project: WorkspaceProject, base = '/'): Plugin[] => {
},
}
},
transform(code, id) {
if (id.includes('loupe/loupe.js')) {
Copy link
Member Author

Choose a reason for hiding this comment

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

We can just bundle loupe to be honest, but then we should probably bundle chai, but I don't see that happening 🤷🏻

Copy link
Contributor

Choose a reason for hiding this comment

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

Just in case, can you clarify the issues with bundling chai?
I guess the obvious one is that it affects vitest's package size. Another one I thought about is that a user code relying on import "chai" would end up with different instance of chai from what Vitest sees internally.
Do you have anything else in mind?

@sheremet-va
Copy link
Member Author

sheremet-va commented Jan 30, 2024

@hi-ogawa what do you think? We don't want Vite to bundle it because it adds an import from util as you pointed out in one of your comments. If we don't bundle patched loupe, then this is the only way I found 🤷🏻

@hi-ogawa
Copy link
Contributor

Oh, I wasn't aware that node builtins were in optimizeDeps.exclude. So, removing that would be necessary for people using node builtin polyfill explicitly, but what was the reason it has been added previously?

From this comment #4892 (comment), I thought we could simply add vitest > @vitest/utils > loupe to optimizeDeps.include. But, after adding this, I'm seeing Vite's warning locally, so this approach might still have other issues.

Module "util" has been externalized for browser compatibility. Cannot access "util.inspect" in client code. See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.

We don't want Vite to bundle it because it adds an import from util as you pointed out in one of your comments.

What do you mean by it adds util?

@sheremet-va
Copy link
Member Author

So, removing that would be necessary for people using node builtin polyfill explicitly, but what was the reason it has been added previously?

We probably forgot to remove it when we provided polyfills ourselves.

What do you mean by it adds util?

It transforms require('util') into import from 'util'. Instead, it should keep it as is.

@sheremet-va sheremet-va merged commit 714c911 into vitest-dev:main Jan 31, 2024
18 of 19 checks passed
@sheremet-va sheremet-va deleted the fixes/browser-builtin-modules branch January 31, 2024 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants