AIStudio: common error

I use AIStudio and all my efforts lately are to avoid major

refactors the inevitably generate an error of the type

“Uncaught TypeError: Failed to resolve module specifier “@/[more here] . Relative references must start with either “/”, “./”, or “../”.”

Invariably the path specified as @/… is not referenced in the app.

Trying to fix this issue has the AI go on a infinite hunt where nothing works – up to the point that it’s admitted to me the development environment it has access to is different than the preview environment.

From Gemini itself:

This error means the browser cannot find a module because its import statement uses a “bare specifier” instead of a relative or absolute path. To fix this, use a build tool like Webpack, Parcel, or Vite to bundle your code, or use import-maps to map bare specifiers to URLs. You can also try using a CDN to import the module directly in an <script type="module"> tag if it’s a third-party library.

Wonder if there is a simple solution (e.g. vite config) that everybody knows about that I don’t.

Hi @Andrea_Moro

Welcome to the Google AI Forum! :confetti_ball: :confetti_ball:

I am sorry to hear that you are facing such problems. I have been using build app consistently for the last few hours and haven’t seen this issue..

Can you share some steps to help me reproduce the issue?

I can’t reproduce it consistently unfortunately.

I could document the next time I encounter it.

I figured it out. The fix is simple.
The error arises when a reference like this is introduced:
import { useNavigationConfig } from ‘../../../contexts/NavigationConfigContext’;

and the simple fix, which the LLM never gets around to do unfortunately, is to avoid any leading ../ and use ./ instead:
import { useNavigationConfig } from ‘./../../contexts/NavigationConfigContext’;

1 Like

Thank you @Andrea_Moro for providing the solution.

As of today, the model is still unable to figure it out on its own btw.