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

Defer importing polyfills (esp. node-fetch) #1

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

tnzk
Copy link

@tnzk tnzk commented Jan 12, 2022

Background

Parcel client cannot be bundled with ViteJS since it fails to pre-bundle a package with dependency to node-specific module. Parcel client has direct dependency to node-fetch, which in turn depends on a bunch of node-specific features, to polyfill fetch.

Solution

  • Defer importing polyfills until just before it is actually used, so Vite won't try to bundle node-specific packages.
  • Use ky-universal to polyfill instead
  • Update Jest config to support ESM and top-level await, which mentioned by code comment in polyfill.ts as the blocker to use ky-universal directly.

My Svelte app works fine with these changes and setting vite.optimizeDeps.exclude to ['node-fetch']. I suppose Vue apps may be the same.

It passes all unit tests that passes at main on my end, but not really confident if this works in node as well.

@tnzk tnzk marked this pull request as draft January 14, 2022 02:18
@tnzk tnzk marked this pull request as ready for review January 14, 2022 07:26
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.

2 participants