Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Conversation

Copy link

Copilot AI commented May 23, 2025

This PR fixes the "Can not use import module" issue by adding proper ES module support to the package while maintaining full backward compatibility with CommonJS.

Problem

Users were unable to use ES6 import syntax in projects configured as ES modules (with "type": "module" in package.json). The package only supported CommonJS require() syntax, causing import errors in modern JavaScript environments.

Solution

Added an exports field to package.json that enables dual module support:

"exports": {
  ".": {
    "import": "./index.js", 
    "require": "./index.js"
  }
}

This tells Node.js how to handle both import styles:

  • CommonJS projects: Can continue using require('streamed-chatgpt-api')
  • ES module projects: Can now use import { fetchStreamedChat } from 'streamed-chatgpt-api'

Verification

Added comprehensive tests to ensure both import methods work correctly:

  • ✅ CommonJS require() works in CommonJS projects
  • ✅ ES6 import works in ES module projects (with "type": "module")
  • ✅ Dynamic imports work in both contexts
  • ✅ All existing functionality preserved
  • ✅ Backward compatibility maintained

Usage Examples

CommonJS (existing usage - unchanged):

const { fetchStreamedChat, fetchStreamedChatContent } = require('streamed-chatgpt-api');

ES Modules (now supported):

import { fetchStreamedChat, fetchStreamedChatContent } from 'streamed-chatgpt-api';

This is a minimal change (6 lines added) that resolves the import compatibility issue without affecting any existing functionality.

Fixes #7.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Can not use import module Add ES module support to fix import compatibility issues May 23, 2025
Copilot AI requested a review from jddev273 May 23, 2025 19:32
Copilot finished work on behalf of jddev273 May 23, 2025 19:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can not use import module

2 participants