Skip to content
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

Issue importing from nodejs / typescript backend #607

Open
2 tasks done
sfakir opened this issue Aug 21, 2023 · 7 comments
Open
2 tasks done

Issue importing from nodejs / typescript backend #607

sfakir opened this issue Aug 21, 2023 · 7 comments

Comments

@sfakir
Copy link

sfakir commented Aug 21, 2023

Verify latest release

  • I verified that the issue exists in the latest chatgpt release

Verify webapp is working

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

@Vagif12
Copy link

Vagif12 commented Aug 24, 2023

I also get this error

@cctv1005s
Copy link

Try set "type": "module" to your package.json?

@Vagif12
Copy link

Vagif12 commented Sep 4, 2023

Still doesn't work @cctv1005s .
This occurs with me when trying to use probot Library

@mmaestrini
Copy link

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?

@SpiritAnri
Copy link

Maybe its export in package.json meteor/meteor#11727 (comment)

@swellee
Copy link

swellee commented Feb 20, 2024

I got the error too.
same within NestJs backend.
has anyone got a resolution?

@rzfzr
Copy link

rzfzr commented Mar 23, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants