I am trying to import Gemini API into my JavaScript module using the following line:
import { GenerativeModel, GoogleGenerativeAI } from "@google/generative-ai";
However, when I run my script containing this, Chrome Developer Tools console throws the following error:
Uncaught TypeError: Failed to resolve module specifier "@google/generative-ai". Relative references must start with either "/", "./", or "../".`
I was expecting the module to be included and the rest of the code to be executed.
I am trying to import Gemini API into my JavaScript module using the following line:
import { GenerativeModel, GoogleGenerativeAI } from "@google/generative-ai";
However, when I run my script containing this, Chrome Developer Tools console throws the following error:
Uncaught TypeError: Failed to resolve module specifier "@google/generative-ai". Relative references must start with either "/", "./", or "../".`
I was expecting the module to be included and the rest of the code to be executed.
Share Improve this question edited Jan 19 at 17:33 Daniel Manta 6,74317 gold badges42 silver badges48 bronze badges asked Jan 18 at 11:15 ShayeqShayeq 51 bronze badge 1- please don't post images of messages or code. Can you replace the image by a code block with the error message itself? – ruud Commented Jan 18 at 15:56
1 Answer
Reset to default 1From the error screenshot format i deduced that you're running your code in a browser. However, the format with @something
(the anisation import), although correct for NodeJS, can't be recognized by browser scripts.
The best way to address this problem would be to use a bundler like Webpack or Vite which is able to convert imports like yours into ESM-compliant ones.
Alternatively, you may use a CDN for a different style of imports:
import { GenerativeModel, GoogleGenerativeAI } from "https://cdn.skypack.dev/@google/generative-ai";