EvanZhouDev / gemini-ai

The simpler JavaScript Gemini SDK
https://www.npmjs.com/package/gemini-ai
GNU General Public License v3.0
95 stars 16 forks source link

I am using CommonJS and i get error (I read the FAQ) #19

Closed MZRCode closed 1 week ago

MZRCode commented 1 week ago

I'm using CommonJS and i am getting the error 'Gemini is not a constructor' even though i am doing it the way you mentioned at the bottom of the FAQ. I'm putting the necessary SS below. Have a nice day.

geminiAI question

EvanZhouDev commented 1 week ago

Sorry, I must have made a small error when typing out that code snippet. It should be fixed now. The callback takes the entire export object, and doesn't automatically give the default. Thus, all you have to do is destructure the callback for default inline and rename it to Gemini again. Something like this should work:

import("gemini-ai").then(async ({ default: Gemini }) => {
    let gemini = new Gemini(API_KEY);
});

I have also updated the FAQ as not to confuse future readers. https://github.com/EvanZhouDev/gemini-ai?tab=readme-ov-file#how-do-i-use-gemini-ai-in-a-cjs-environment

Thank you for pointing this out!