transitive-bullshit / agentic

AI agent stdlib that works with any LLM and TypeScript AI SDK.
https://agentic.so
MIT License
16.49k stars 2.15k forks source link

^ Error [ERR_REQUIRE_ESM]: require() of ES Module #56

Closed wsdo closed 1 year ago

wsdo commented 1 year ago

use nestjs

const chatgpt_1 = require("chatgpt"); ^ Error [ERR_REQUIRE_ESM]: require() of ES Module

transitive-bullshit commented 1 year ago

From the readme:

async function example() {
  // To use ESM in CommonJS, you can use a dynamic import
  const { ChatGPTAPI } = await import('chatgpt')

  const api = new ChatGPTAPI({
    sessionToken: process.env.SESSION_TOKEN
  })
  await api.ensureAuth()

  const response = await api.sendMessage('Hello World!')
  console.log(response)
}

(This project does not support a commonjs export because it is deprecated for all intents and purposes and is a pain for maintainers to support.)

h-gyeom commented 1 year ago

It doesn't work in nestjs framework. It still emit error "const { ChatGPTAPI } = await Promise.resolve().then(() => __importStar(require('chatgpt')));"

transitive-bullshit commented 1 year ago

@h-gyeom other people have posted the same thing and gotten it to work with nestjs. Please search the github issues.

mitkodkn commented 1 year ago

I created a starter repository for NestJS + ChatGPT: https://github.com/mitkodkn/nestjs-chatgpt-starter

Hope it helps.