agentic
agentic copied to clipboard
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported.
node-fetch
v3 can't use require(), can downgrade to v2.6.7
I just released an update which removes commonjs support: https://github.com/transitive-bullshit/chatgpt-api/releases/tag/v1.1.0
I was against this idea in https://github.com/transitive-bullshit/chatgpt-api/pull/8, and I'm not surprised it ended up causing problems.
@GoneTone please let me know if v1.1.0
solves your issues. You won't be able to require('chatgpt')
. Instead, you need to follow the readme and use import { ChatGPTAPI } from 'chatgpt'
I'm using it in my Discord bot, project using require()...
Hey @transitive-bullshit, great work with this package as well as all your work with React Notion.
I just upgraded to 1.1.0
and am still seeing this issue. My import is in the suggested format as well:
import { ChatGPTAPI } from 'chatgpt';
Lmk if I can provide more information. Although, I do think the easiest option is probably to go with v2 of node-fetch
to widen support for this package.
Ahhh my bad. Just downgraded to v2 https://github.com/transitive-bullshit/chatgpt-api/releases/tag/v1.1.1
@GoneTone can you try https://github.com/transitive-bullshit/chatgpt-api/releases/tag/v1.1.2? I just re-added commonjs support along with having the downgraded node-fetch
v2.
Sorry for all the confusion and version bumps.
@GoneTone can you try https://github.com/transitive-bullshit/chatgpt-api/releases/tag/v1.1.2? I just re-added commonjs support along with having the downgraded
node-fetch
v2.
it's not working
@14kk can you please give me a more detailed error you're seeing and/or code to reproduce the error?
remark
Error [ERR_REQUIRE_ESM]: require() of ES Module E:\...\node_modules\remark\index.js from E:\...\node_modules\chatgpt\build\index.js not supported.
encounter the same problem.
"chatgpt": "^1.1.2", "node-fetch": "^2.6.7",
Okay; for now, I'm going to disable commonjs support because it is not working via https://github.com/transitive-bullshit/chatgpt-api/releases/tag/v1.1.3
If you are currently using require('chatgpt')
, you'll need to upgrade to the latest 1.1.3
and follow this guide in order to use the ESM version: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
I'm sorry if this is an inconvenience for you, but it was my original intention to only support ESM as many other packages in the NPM ecosystem are increasingly doing.
If you are still having an issue using 1.1.3
or later and are using the ESM version via import { ChatGPTAPI } from 'chatgpt'
, please let me know with as much detail as possible — including a link to your code so I can try to reproduce any issues. I'm using the ESM version in https://github.com/transitive-bullshit/chatgpt-twitter-bot and have verified that the version on NPM is working as expected.
@transitive-bullshit I am on 1.1.3 and still seeing an error when I try to start my app. I believe it has something to do with the type
being set to module
here: https://github.com/transitive-bullshit/chatgpt-api/blob/main/package.json#L8
You can view the output here: https://app.warp.dev/block/cJcagd7Gq7bwEldsZLmYpR
@FarazPatankar your code is being transpiled / loaded as commonjs.
@transitive-bullshit I successfully modified chatgpt-api
to support cjs, wait I will open a pull request!
@transitive-bullshit I successfully modified
chatgpt-api
to support cjs, wait I will open a pull request!
can't wait for it
@transitive-bullshit I successfully modified
chatgpt-api
to support cjs, wait I will open a pull request!can't wait for it
+1
https://github.com/transitive-bullshit/chatgpt-api/pull/19
Please use v1.3.0
which includes support for CommonJS via #19.
Thanks @GoneTone 🙏
If you run into an issue with v1.3.0
and commonjs, please open a separate issue to discuss and provide as many details about your environment as possible — including a minimal reproduction if possible.
I use chatgpt-api package in my project which is based on typescript. When I'm going to run my code with ts-node index.ts
, the error encountered:
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/tanknee/Documents/LocalCodeRepo/chatgpt-padlocal/node_modules/chatgpt/build/index.js from /Users/tanknee/Documents/LocalCodeRepo/chatgpt-padlocal/chatgpt.ts not supported.
Instead change the require of index.js in /Users/tanknee/Documents/LocalCodeRepo/chatgpt-padlocal/chatgpt.ts to a dynamic import() which is available in all CommonJS modules.
My code used ESM like
import { ChatGPTAPI, ChatGPTConversation } from 'chatgpt';
import { SESSION_TOKEN } from './configs';
import log4js from './logger';
I use chatgpt-api package in my project which is based on typescript. When I'm going to run my code with
ts-node index.ts
, the error encountered:Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/tanknee/Documents/LocalCodeRepo/chatgpt-padlocal/node_modules/chatgpt/build/index.js from /Users/tanknee/Documents/LocalCodeRepo/chatgpt-padlocal/chatgpt.ts not supported. Instead change the require of index.js in /Users/tanknee/Documents/LocalCodeRepo/chatgpt-padlocal/chatgpt.ts to a dynamic import() which is available in all CommonJS modules.
My code used ESM like
import { ChatGPTAPI, ChatGPTConversation } from 'chatgpt'; import { SESSION_TOKEN } from './configs'; import log4js from './logger';
When I use tsx instead of ts-node, the code works.
it is like ES module dictatorship.
is it possible to use it with regular require?
I was able to fix this in typescript(express js) by installing tsx in devDependencies and changing my scripts to "scripts": { "dev": "tsx watch src/index.ts", "build": "tsc", "start": "tsx dist/index.js" } and installing node >= 18
I have this problem to this day, how do I solve it?
[1] Instead change the require of index.js in ... to a dynamic import() which is available in all CommonJS modules.```