-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
webpack bundle error #69
Comments
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 commonjs exports because they are deprecated for all intents and purposes and it is a huge pain for maintainers to support.) Here's a solid guide on other ways to use ESM modules like |
@PengBoUESTC ESM modules can import commonjs modules, but commonjs cannot synchronously import ESM modules. |
that's may be my fault, build tool transform import to require |
reduce the size of docker image by deleting cache files
I believe it was the case with This solved it for me! |
webpack 5.66.0 compiled successfully in 3940 ms
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: xxx/node_modules/chatgpt/build/index.js
require() of ES modules is not supported.
require() of xxx/node_modules/chatgpt/build/index.js from xxx/dist/src/modules/chat/Chat.service.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from xxx/node_modules/chatgpt/package.json.
The text was updated successfully, but these errors were encountered: