Francesco Zanoncelli
Francesco Zanoncelli

Reputation: 147

Can't find variable: require at global code@

I'm new to JavaScript and was trying to import the Google Gemini library to use its AI. However, I'm facing an issue when I use the "require" keyword:

ERROR: Can't find variable: require at global code@

Here is the code that throws this error:

const {
    GoogleGenerativeAI,
    // HarmCategory,
    // HarmBlockThreshold,
  } = require("@google/generative-ai");

Upvotes: 2

Views: 110

Answers (1)

9BallOnTheSnap
9BallOnTheSnap

Reputation: 599

Try removing

const {
  GoogleGenerativeAI,
  HarmCategory,
  HarmBlockThreshold,
} = require("@google/generative-ai");

And replace with

import { GoogleGenerativeAI } from "@google/generative-ai";

Upvotes: -1

Related Questions