agentic icon indicating copy to clipboard operation
agentic copied to clipboard

ERROR 7790 nodejs.ERR_REQUIRE_ESMError

Open FEjohnny opened this issue 3 years ago • 1 comments

Verify latest release

  • [X] I verified that the issue exists in the latest chatgpt release

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.

FEjohnny avatar Feb 07 '23 13:02 FEjohnny

It's also happening on my setup.

Environment:

node: v18.14.0 "chatgpt": "^4.1.3" "typescript": 4.9.5

xjeeh avatar Feb 07 '23 15:02 xjeeh

@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.

xjeeh avatar Feb 07 '23 19:02 xjeeh

Hum.. I'm getting this same error working in Remix. Node: v18.12.1 "chatgpt": "^4.2.0", "typescript": "^4.8.4"

fourcolors avatar Feb 08 '23 06:02 fourcolors

I'm getting this error, too.

brianyun avatar Feb 08 '23 08:02 brianyun

"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"
	}

brianyun avatar Feb 08 '23 08:02 brianyun

@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.

yeah, but I try to add "type": "module" into package.json, it dosen't work.

FEjohnny avatar Feb 08 '23 08:02 FEjohnny

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.

otakustay avatar Feb 08 '23 09:02 otakustay

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.

transitive-bullshit avatar Feb 08 '23 09:02 transitive-bullshit