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

Critical dependency: the request of a dependency is an expression #451

Closed
2 tasks done
xithalius opened this issue Mar 8, 2023 · 3 comments
Closed
2 tasks done

Comments

@xithalius
Copy link

xithalius commented Mar 8, 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

Vercel Edge Functions - Node 18.x

Describe the Bug

As soon as I try to create a ChatGPTAPI instance I'm getting the following error.

error - node_modules/keyv/src/index.js (37:0) @ <unknown>
error - Class extends value #<Object> is not a constructor or null
null
warn  - ./node_modules/keyv/src/index.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
./node_modules/keyv/src/index.js
./node_modules/chatgpt/build/index.js

I might be doing something wrong, is there a Vercel Edge Function example using this package I can take a look at?

Sample code:

import { ChatGPTAPI } from 'chatgpt';
import { NextRequest, NextResponse } from 'next/server';

export const config = {
  runtime: 'edge',
};

const handler = async (req: NextRequest, res: NextResponse) => {
  const api = new ChatGPTAPI({
    apiKey: process.env.OPENAI_API_KEY ?? '',
  });

  return new Response(JSON.stringify({}), {
    status: 200,
  });
};

export default handler;
@transitive-bullshit
Copy link
Owner

This is likely related to #413

Also, I'm pretty sure keyv isn't compatible with edge functions. You'd have to switch to using a standard serverless function for now.

If this is a high enough issue that affects others, I may consider swapping keyv for an edge-compatible solution.

@xithalius
Copy link
Author

Yes, now that I see it, it is indeed related to #413. Although I did use pages/api (API Route) instead of the new Next.js 13 Route Handler (hence I created a new issue). So #413 is not a Next.js bug but is environment related I suppose. Will close this awaiting Edge support. (Vercel) Serverless Functions are not an option for me as they do not support streaming.

@MaxLeiter
Copy link

hey @xithalius, just an fyi that Vercel Serverless Functions do support streaming: https://vercel.com/blog/streaming-for-serverless-node-js-and-edge-runtimes-with-vercel-functions

@transitive-bullshit I'm another user who would like to use this library in an edge function

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

3 participants