-
Notifications
You must be signed in to change notification settings - Fork 1
Labels
bugSomething isn't workingSomething isn't working
Description
Bug Description
use-m fails to load on Windows in GitHub Actions and certain Node.js contexts with the error "fetch is not defined".
Environment
- Platform: Windows (windows-latest on GitHub Actions)
- Node.js Version: 20.x
- Shell: Git Bash (bash shell on Windows)
- Context: Running scripts with shebang
#!/usr/bin/env node
Error
When trying to load use-m with the standard approach:
globalThis.use = (await eval(await (await fetch('https://unpkg.com/use-m/use.js')).text())).use;The script fails with:
ReferenceError: fetch is not defined
Root Cause Analysis
While Node.js 18+ has built-in fetch support, it appears that in certain Windows contexts (particularly Git Bash or when scripts are executed via shebang), the fetch global may not be available.
Reproduction
- Create a file
test.mjswith:
#!/usr/bin/env node
console.log('Node version:', process.version);
console.log('Fetch available:', typeof fetch !== 'undefined');
if (typeof use === 'undefined') {
globalThis.use = (await eval(await (await fetch('https://unpkg.com/use-m/use.js')).text())).use;
}- Run on Windows with Git Bash:
./test.mjs- Observe the error about fetch not being defined
Test Case
See reproduction script: https://github.com/deep-assistant/hive-mind/blob/main/use-m-issues/issue-04-windows-fetch-undefined.mjs
Workaround Attempts
- node-fetch polyfill: Doesn't work because use-m uses eval context
- Direct node execution: Using
node script.mjsinstead of./script.mjssometimes helps - Environment check: Detecting and handling missing fetch before use-m load
Suggested Fix
Consider one of:
- Check for fetch availability inside use-m and provide a helpful error
- Bundle a fetch polyfill within use-m for compatibility
- Use alternative loading method that doesn't require fetch (e.g., require/import)
- Document the Node.js 18+ requirement and Windows limitations
Impact
This prevents use-m from working in Windows CI/CD pipelines and affects cross-platform compatibility of projects using use-m.
Related Issues
- Similar issue reported in deep-assistant/hive-mind: https://github.com/deep-assistant/hive-mind/tree/main/use-m-issues
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working