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

deps(browser): remove modern-node-polyfills package #3648

Merged
merged 1 commit into from Sep 27, 2023

Conversation

Marcel-G
Copy link
Contributor

@Marcel-G Marcel-G commented Jun 23, 2023

resolves: #3299

The browser runner indiscriminately applies pollyfills for node builtin modules. This PR removes completely removes the dependence on modern-node-polyfills.

@Marcel-G Marcel-G marked this pull request as ready for review June 23, 2023 07:26
@sheremet-va
Copy link
Member

sheremet-va commented Jun 27, 2023

We don't rely on util in #3685 anymore, so we can also remove polyfills now with modern-node-polyfills package

@Marcel-G

This comment was marked as resolved.

@userquin
Copy link
Member

The name of this plugin now doesn't seem appropriate, any naming ideas?

vitest:browser:tests

@Marcel-G

This comment was marked as resolved.

@sheremet-va
Copy link
Member

sheremet-va commented Jun 29, 2023

As far as I can tell util is still included by @sinonjs/fake-timers:

this._fakeTimers = withGlobal(global)

  1. util is included dynamically if running inside Node.js
  2. We bundle @sinonjs/fake-timers

@Marcel-G

This comment was marked as resolved.

@sheremet-va
Copy link
Member

Heres the error in the browser if we don't include util pollyfil

__vite-browser-external:util:3 Uncaught (in promise) Error: Module "util" has been externalized for browser compatibility. Cannot access "util.default" in client code.  See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
    at Object.get (__vite-browser-external:util:3:11)
    at withGlobal (vendor-vi.f4f5ef45.js:1370:47)
    at vendor-vi.f4f5ef45.js:3017:32
    at vendor-vi.f4f5ef45.js:3023:3

Probably because we have process mocked, which we also shouldn't do, but it should be addressed in a separate issue.

@Marcel-G Marcel-G changed the title fix: omit node built-in pollyfills in browser deps(browser): remove modern-node-polyfills package Jun 29, 2023
@Marcel-G
Copy link
Contributor Author

Probably because we have process mocked, which we also shouldn't do, but it should be addressed in a separate issue.

Something like this #3701?

@sheremet-va
Copy link
Member

Probably because we have process mocked, which we also shouldn't do, but it should be addressed in a separate issue.

Something like this #3701?

Yes

@sheremet-va
Copy link
Member

Heres the error in the browser if we don't include util pollyfil

Why are tests passing then 🤔

@Marcel-G

This comment was marked as resolved.

@Marcel-G
Copy link
Contributor Author

OK, the tests will fail until #3701 is in

Copy link
Member

@sheremet-va sheremet-va left a comment

Choose a reason for hiding this comment

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

normalizeId is not used anymore

@netlify
Copy link

netlify bot commented Jun 30, 2023

Deploy Preview for fastidious-cascaron-4ded94 ready!

Name Link
🔨 Latest commit 0f333f8
🔍 Latest deploy log https://app.netlify.com/sites/fastidious-cascaron-4ded94/deploys/650d90ed8063f40008426c62
😎 Deploy Preview https://deploy-preview-3648--fastidious-cascaron-4ded94.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Marcel-G
Copy link
Contributor Author

Marcel-G commented Jul 7, 2023

normalizeId is not used anymore

Very true! Removed ✅

@Marcel-G
Copy link
Contributor Author

@sheremet-va are the tests generally a bit flakey? It seems to be a different spec failing each time

@sheremet-va
Copy link
Member

@sheremet-va are the tests generally a bit flakey? It seems to be a different spec failing each time

Some tests are flaky. Your PR is open until we have a browser test in ecosystem-ci

@Marcel-G
Copy link
Contributor Author

Marcel-G commented Sep 4, 2023

Some tests are flaky. Your PR is open until we have a browser test in ecosystem-ci

@sheremet-va what is the status of that? is it something I can help with?

@sheremet-va
Copy link
Member

Some tests are flaky. Your PR is open until we have a browser test in ecosystem-ci

@sheremet-va what is the status of that? is it something I can help with?

Sorry for keeping you waiting! I am working on a small test suite for ecosystem-ci now, we can probably merge this PR today or next week.

@sheremet-va sheremet-va merged commit dd98279 into vitest-dev:main Sep 27, 2023
14 of 17 checks passed
@Marcel-G Marcel-G deleted the fix/omit-node-polyfills branch September 28, 2023 08:43
@AriPerkkio
Copy link
Member

AriPerkkio commented Oct 3, 2023

How should the util be polyfilled now? It's still used by @sinonjs/fake-timers. v1-beta fails with error SyntaxError: The requested module '/node_modules/.pnpm/util@0.12.5/node_modules/util/util.js?v=c8f99d41' does not provide an export named '__vi_inject__'. And when adding "vitest > util" to optimizeDeps.include, it fails with:

ReferenceError: process is not defined
 ❯ node_modules/.pnpm/util@0.12.5/node_modules/util/util.js ../../../../node_modules/.vite/deps/vitest___util.js:1308:5
 ❯ __require ../../../../node_modules/.vite/deps/chunk-UXIASGQL.js:9:50
 ❯ ../../../../node_modules/.vite/deps/vitest___util.js:1799:25

@sheremet-va
Copy link
Member

How should the util be polyfilled now?

Vitest doesn't use it and as far as I know @sinonjs/fake-timers checks it at runtime, so this shouldn't be a problem? If it is, maybe we can patch it and inline the package?

And when adding "vitest > util" to optimizeDeps.include, it fails with:

The error looks correct to me since we don't define a global process variable since it doesn't exist in the browser.

@AriPerkkio
Copy link
Member

AriPerkkio commented Oct 3, 2023

Vitest doesn't use it

Looks like @vitest/browser imports vitest/runners, which uses vi. Importing vi brings in inlined fake-timers which has process. The vendor-vi has import require$$2 from 'util';.

@sheremet-va
Copy link
Member

Vitest doesn't use it

Looks like @vitest/browser imports vitest/runners, which uses vi. Importing vi brings in inlined fake-timers which has process. The vendor-vi has import require$$2 from 'util';.

fake-timers have a check for process. What I assume happened in your case is that polyfill is using process for some reason.

The vendor-vi has import require$$2 from 'util';.

Yeah, this is why I am saying we should just patch fake timers to remove this check.

LorenzoBloedow pushed a commit to LorenzoBloedow/vitest that referenced this pull request Dec 19, 2023
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.

Remove polyfills in browser mode
4 participants