Skip to content

fix: use native fetch instead of node-fetch for Node 18+ compatibility#70

Merged
JdaieLin merged 1 commit into
PiSugar:masterfrom
tjaffri:fix/node-fetch-esm-compatibility
May 11, 2026
Merged

fix: use native fetch instead of node-fetch for Node 18+ compatibility#70
JdaieLin merged 1 commit into
PiSugar:masterfrom
tjaffri:fix/node-fetch-esm-compatibility

Conversation

@tjaffri

@tjaffri tjaffri commented May 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Removes the node-fetch dependency from proxy-fetch module
  • Uses Node.js native fetch (available since Node 18)
  • Continues to support proxy via undici's ProxyAgent when configured

Problem

node-fetch v3 is ESM-only, which causes errors when used in CommonJS projects with Node 18+:

require() of ES Module .../node_modules/node-fetch/src/index.js not supported.

This breaks OpenAI API calls and other cloud API integrations.

Solution

Since the project targets Node 20 (installed via install_dependencies.sh), we can use the native fetch API instead of node-fetch. This eliminates the ESM compatibility issue while maintaining proxy support.

Test plan

  • Tested with Node 22 on macOS
  • Verified OpenAI LLM/ASR/TTS calls work correctly
  • Verified proxy support still works via undici ProxyAgent

🤖 Generated with Claude Code

node-fetch v3 is ESM-only, which causes "require() of ES Module not
supported" errors when used in CommonJS projects with Node 18+.

This change:
- Removes the node-fetch dependency from proxy-fetch
- Uses Node.js native fetch (available since Node 18)
- Continues to support proxy via undici's ProxyAgent when configured

Since the project targets Node 20, native fetch is always available.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@JdaieLin JdaieLin merged commit 5bce47f into PiSugar:master May 11, 2026
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