transitive-bullshit / agentic

AI agent stdlib that works with any LLM and TypeScript AI SDK.
MIT License
16.07k stars 2.11k forks source link

Issue importing from nodejs / typescript backend #607

Closed sfakir closed 1 month ago

sfakir commented 11 months ago

Verify latest release

Verify webapp is working

Environment details

Describe the Bug

Importing the chatGPT module does not work. It thoughts the error below.

reproducable:

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 commented 11 months ago

I also get this error

cctv1005s commented 10 months ago

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

Vagif12 commented 10 months ago

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

mmaestrini commented 10 months ago

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 commented 9 months ago

Maybe its export in package.json https://github.com/meteor/meteor/discussions/11727#discussioncomment-2199815

swellee commented 5 months ago

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

rzfzr commented 4 months ago

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?

transitive-bullshit commented 1 month ago

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.