Is it possible to import third-party libraries in extensions?

I’m trying to create a GNOME extension for https://activitywatch.net, and for that I need to import their library (GitHub - ActivityWatch/aw-client-js: Client library for ActivityWatch in JavaScript). Is it possible to do that from a GNOME extension? If I just add the library as a git submodule, I can’t import it, neither via the GJS imports object or via JavaScript import. How can I use the library in my extension?

See this reply, it may be of interest:

Can you help me with this? I tried the following rollup.config.mjs:

import commonjs from "@rollup/plugin-commonjs";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import json from "@rollup/plugin-json";
import nodePolyfills from 'rollup-plugin-node-polyfills';

export default {
    input: 'node_modules/aw-client/out/aw-client.js',
    output: {
        file: 'activitywatch.js',
    },
    plugins: [
        nodeResolve(),
        commonjs(),
        json(),
        nodePolyfills(),
    ],
};

But I got an error saying something like “export declarations can only be at the top level of a module”

You may want to read through the documentation for GJS’s ES Module support. Note that using ESM in a GNOME Shell extension may not work, as GNOME Shell has not yet been migrated from the import system we started using before ESM existed.

A very small number of people have done this, but you will be mixing two types of import systems.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.