Issue importing from nodejs / typescript backend
sfakir opened this issue · comments
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
...
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 meteor/meteor#11727 (comment)
I got the error too.
same within NestJs backend.
has anyone got a resolution?