Fix: Add fetch polyfill for Windows - fetch is not defined in certain Node.js contexts#46
Open
Fix: Add fetch polyfill for Windows - fetch is not defined in certain Node.js contexts#46
Conversation
Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: #45
This commit addresses issue #45 where fetch is not defined in certain Windows contexts (Git Bash, shebang execution) even in Node.js 18+. Changes: - Add Windows (windows-latest) to GitHub Actions test matrix - Create fetch-polyfill.js module that provides fetch for environments where it's missing - Add examples demonstrating the workaround (test-with-polyfill.mjs, test-without-polyfill.mjs) - Add experiment scripts for testing fetch availability and polyfill behavior - Update package.json exports to include fetch-polyfill.js The fetch polyfill: 1. Checks if fetch is available in globalThis 2. If not, tries to use undici (Node.js 18+ built-in) 3. Falls back to node:http/https with proper redirect handling 4. Provides a fetch-compatible API (text(), json(), status, etc.) Usage: await import('use-m/fetch-polyfill.js'); const { use } = eval(await (await fetch('https://unpkg.com/use-m/use.js')).text()); 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Member
Author
✅ Implementation CompleteI've successfully implemented a solution for issue #45 - fetch is not defined on Windows in certain Node.js contexts. 📦 What Was Delivered
🧪 TestingLocal Tests: ✅ Passed
CI Status: ⏳ Running
📝 Usage Example#!/usr/bin/env node
// Import the polyfill first (only needed if fetch might be missing)
await import('use-m/fetch-polyfill.js');
// Now use-m works normally
const { use } = eval(await (await fetch('https://unpkg.com/use-m/use.js')).text());
const _ = await use('lodash@4.17.21');
console.log(_.add(1, 2)); // 3🔗 Pull RequestReady for review! 🚀 |
This reverts commit e2ae686.
Member
Author
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 📎 Log file uploaded as GitHub Gist (371KB) Now working session is ended, feel free to review and add any feedback on the solution draft. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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