Fix: Add fetch polyfill for Windows - fetch is not defined in certain Node.js contexts #46
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🎯 Solution Overview
This PR fixes issue #45 where
fetch is not definedin certain Windows contexts (Git Bash, shebang execution) even in Node.js 18+.📋 Issue Reference
Fixes #45
🔍 Root Cause
While Node.js 18+ has built-in fetch support, it may not be available in the global scope in certain Windows contexts:
#!/usr/bin/env nodein Git Bash on Windows✨ Implementation
1. Fetch Polyfill Module (
fetch-polyfill.js)fetchis missing fromglobalThisundici(Node.js 18+ built-in fetch implementation)node:http/node:httpswith a fetch-compatible wrappertext(),json(),blob(),arrayBuffer()2. Windows CI Support
windows-latestto GitHub Actions test matrix3. Examples and Documentation
examples/windows-fetch-workaround/test-with-polyfill.mjs- Demonstrates the fixexamples/windows-fetch-workaround/test-without-polyfill.mjs- Shows the issueexperiments/folder with comprehensive test scripts📝 Usage
Before (fails on Windows Git Bash):
After (works everywhere):
🧪 Testing
Experiment Scripts:
experiments/test-fetch-availability.mjs- Tests if fetch is availableexperiments/test-fetch-polyfill.mjs- Tests polyfill with full use-m workflowexperiments/test-polyfill-no-fetch.mjs- Simulates missing fetch scenarioTest Results:
✅ Polyfill correctly detects missing fetch
✅ Polyfill installs fetch using undici or http/https fallback
✅ Polyfill handles HTTP redirects properly
✅ use-m loads successfully with polyfilled fetch
✅ Packages can be imported and used normally
📦 Changes
fetch-polyfill.js- Standalone polyfill modulepackage.json- Added fetch-polyfill.js to exports.github/workflows/test.yml- Added windows-latest to matrix🔄 Next Steps
🤖 Generated with Claude Code