ERROR 7790 nodejs.ERR_REQUIRE_ESMError
Verify latest release
- [X] I verified that the issue exists in the latest
chatgptrelease
Verify webapp is working
- [X] I verify that the ChatGPT webapp is working properly for this account.
Environment details
node version: v16.19.0 "chatgpt": "^4.1.1", "typescript": "^4.6.3"
Describe the Bug
import { ^ Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/johnny/Documents/personal/chatgpt/server/node_modules/chatgpt/build/index.js from /Users/johnny/Documents/personal/chatgpt/server/app/controller/ChatController.ts not supported.
It's also happening on my setup.
Environment:
node: v18.14.0 "chatgpt": "^4.1.3" "typescript": 4.9.5
@FEjohnny I changed my npm start script to npx tsx index.ts and it worked.
So I believe we've missed some ESM config in our projects.
Hum.. I'm getting this same error working in Remix. Node: v18.12.1 "chatgpt": "^4.2.0", "typescript": "^4.8.4"
I'm getting this error, too.
"dependencies": {
"chatgpt": "4.1.1",
"express": "4.18.2",
"dotenv": "16.0.3"
},
"devDependencies": {
"@types/express": "4.17.17",
"@types/mocha": "10.0.1",
"@types/node": "18.11.19",
"mocha": "10.2.0",
"nodemon": "2.0.20",
"ts-node": "10.9.1",
"typescript": "4.9.5"
}
@FEjohnny I changed my npm start script to
npx tsx index.tsand it worked. So I believe we've missed some ESM config in our projects.
yeah, but I try to add "type": "module" into package.json, it dosen't work.
For node in CJS mode to use, this lib has to publish a dual format (ESM + CJS). Moving an existing project to pure ESM can be very hard.
If acceptable, I can help to make it dual format, I have worked this out several times in the past, not a difficult stuff.
Please search the existing issues.
This module will not support commonjs and I have good reasons for that which I've explained previously. The readme even includes instructions on how to use this module from commonjs.