Closed pospile closed 1 year ago
Found out solution from previous issues.
Heres what helped me:
Dynamic import:
const importDynamic = new Function( 'modulePath', 'return import(modulePath)', );
and then
const { ChatGPTUnofficialProxyAPI } = await importDynamic("chatgpt");
Found out solution from previous issues.
Heres what helped me:
Dynamic import:
const importDynamic = new Function( 'modulePath', 'return import(modulePath)', );
and thenconst { ChatGPTUnofficialProxyAPI } = await importDynamic("chatgpt");
Thanks. Your suggestion works, whereas just doing await import("chatgpt")
as is suggested in the official README.md does not work and fails with:
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/wstein/build/cocalc/src/data/projects/812abe34-a382-4bd1-9071-29b6f4334f03/cocalc/src/packages/node_modules/.pnpm/chatgpt@5.0.10/node_modules/chatgpt/build/index.js from /Users/wstein/build/cocalc/src/data/projects/812abe34-a382-4bd1-9071-29b6f4334f03/cocalc/src/packages/server/dist/openai/chatgpt.js not supported.
Instead change the require of index.js in /Users/wstein/build/cocalc/src/data/projects/812abe34-a382-4bd1-9071-29b6f4334f03/cocalc/src/packages/server/dist/openai/chatgpt.js to a dynamic import() which is available in all CommonJS modules.
at /Users/wstein/build/cocalc/src/data/projects/812abe34-a382-4bd1-9071-29b6f4334f03/cocalc/src/packages/server/dist/openai/chatgpt.js:32:76
at async Object.demo (/Users/wstein/build/cocalc/src/data/projects/812abe34-a382-4bd1-9071-29b6f4334f03/cocalc/src/packages/server/dist/openai/chatgpt.js:32:28) {
code: 'ERR_REQUIRE_ESM'
}
I wish the README.md suggested the above workaround instead, and greatly appreciate that you did.
Found out solution from previous issues.
Heres what helped me:
Dynamic import:
const importDynamic = new Function( 'modulePath', 'return import(modulePath)', );
and thenconst { ChatGPTUnofficialProxyAPI } = await importDynamic("chatgpt");
thanks. this is the ONLY thing what actually fixed it.
Good solution, too bad it doesn't support types for typescript
await import("chatgpt")
is not work.
I found another way:
const { ChatGPTAPI } = await (eval('import("chatgpt")') as Promise<typeof import('chatgpt')>);
Verify latest release
chatgpt
releaseVerify webapp is working
Environment details
Node 18, macOS, using latest FoalTS framework
Describe the Bug
Error [ERR_REQUIRE_ESM]: require() of ES Module
even when importing as:
const { ChatGPTUnofficialProxyAPI } = await import('chatgpt');
as per documentation.
Any idea why?