gjs

Difference between "import" and "imports" in GJS


gjs.guide recommends writing GJS import statements like this:

const Gtk = imports.gi.Gtk;

while most actual code that I see, and also the built-in Gnome Builder templates have this:

import Gtk from 'gi://Gtk';

What's the difference between the two? When should I prefer one over the other?


Solution

  • After bumming around in the gjs repository for a while I've stumbled upon this file: doc/ESModules.md

    In it they refer to "imports" as the legacy way of importing modules. From what I understood from that document: