agentic
agentic copied to clipboard
Issue importing from nodejs / typescript backend
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 18
- NestJS Typescript
Describe the Bug
Importing the chatGPT module does not work. It thoughts the error below.
reproducable:
- import { ChatGPTAPI } from 'chatgpt';
- const chatgptAPI = new ChatGPTAPI({ apiKey: process.env.OPENAI_API_KEY });
Error:
@nx/js/src/executors/node/node-with-require-overrides.js:18 return originalLoader.apply(this, arguments);
Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules/chatgpt/build/index.js from brain-api/main.js not supported. Instead change the require of index.js in apps/brain-api/main.js to a dynamic import() which is available in all CommonJS modules. at Module._load (node_modules/@nx/js/src/executors/node/node-with-require-overrides.js:18:31) at Object.defineProperty.value (react/dist/apps/brain-api/main.js:794:18) at webpack_require (dist/apps/brain-api/ma ...
I also get this error
Try set "type": "module"
to your package.json?
Still doesn't work @cctv1005s . This occurs with me when trying to use probot Library
very annoying :( same problem, if i change type to module i get:
module.exports = require("@nestjs/core"); ^ ReferenceError: require is not defined in ES module scope, you can use import instead This file is being treated as an ES module because it has a '.js' file extension ...
How do we fix it?
Maybe its export in package.json https://github.com/meteor/meteor/discussions/11727#discussioncomment-2199815
I got the error too. same within NestJs backend. has anyone got a resolution?
This has been a way to make it work on Electron's backend:
import './fetch-polyfill.js'
import { log } from './logger'
const { ChatGPTAPI } = await import(/* webpackIgnore: true */'chatgpt')
const api = new ChatGPTAPI({ apiKey: 'sk-...
but it only works in development, on a built project I get this:
Cannot find package 'chatgpt' imported from C:\Users\...\background.js
Did you mean to import chatgpt/build/index.js?
Any ideas?
This project is undergoing a major revamp; closing out old issues as part of the prep process.
The chatgpt
package is pretty outdated at this point. I recommend that you use the openai package or the openai-fetch package instead.