From 57a1d6e3cd0683aa14fc57bfc6b36126ad65d071 Mon Sep 17 00:00:00 2001 From: Kid <44045911+kidonng@users.noreply.github.com> Date: Thu, 23 Mar 2023 20:43:47 +0800 Subject: [PATCH] fix: ESM error (#826) --- service/package.json | 2 +- service/src/chatgpt/index.ts | 4 +++- service/tsup.config.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/service/package.json b/service/package.json index 4089b9e..d457c7b 100644 --- a/service/package.json +++ b/service/package.json @@ -16,7 +16,7 @@ "scripts": { "start": "esno ./src/index.ts", "dev": "esno watch ./src/index.ts", - "prod": "esno ./build/index.js", + "prod": "node ./build/index.mjs", "build": "pnpm clean && tsup", "clean": "rimraf build", "lint": "eslint .", diff --git a/service/src/chatgpt/index.ts b/service/src/chatgpt/index.ts index 62e4b03..c702e6a 100644 --- a/service/src/chatgpt/index.ts +++ b/service/src/chatgpt/index.ts @@ -3,7 +3,7 @@ import 'isomorphic-fetch' import type { ChatGPTAPIOptions, ChatMessage, SendMessageOptions } from 'chatgpt' import { ChatGPTAPI, ChatGPTUnofficialProxyAPI } from 'chatgpt' import { SocksProxyAgent } from 'socks-proxy-agent' -import { HttpsProxyAgent } from 'https-proxy-agent' +import httpsProxyAgent from 'https-proxy-agent' import fetch from 'node-fetch' import axios from 'axios' import { sendResponse } from '../utils' @@ -11,6 +11,8 @@ import { isNotEmptyString } from '../utils/is' import type { ApiModel, ChatContext, ChatGPTUnofficialProxyAPIOptions, ModelConfig } from '../types' import type { RequestOptions } from './types' +const { HttpsProxyAgent } = httpsProxyAgent + dotenv.config() const ErrorCodeMessage: Record = { diff --git a/service/tsup.config.ts b/service/tsup.config.ts index 4f24c6a..534f06d 100644 --- a/service/tsup.config.ts +++ b/service/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ['src/index.ts'], outDir: 'build', target: 'es2020', - format: ['cjs'], + format: ['esm'], splitting: false, sourcemap: true, minify: false,