Import other npm libraries in plugin

Hi,

I am starting my first obsidian plugin trials but struggle with some basic stuff. I am familiar with typescript and nodejs on the command line. Bundling etc. is new for me.

I used the sample plugin and installed vis-network dependency with npm.

In the plugin I want to use the library, for example just create an object from vis-network:

import { Plugin } from "obsidian";
import { DataSet } from "vis-network";

export default class MyPlugin extends Plugin {
	async onload() {
		console.log(new DataSet({}));
	}
}

Whenever I enable the plugin in Obsidian, I get an error on the console:

plugin:obsidian-sample-plugin:41677 Uncaught (in promise) TypeError: import_vis_network.DataSet is not a constructor
    at MyPlugin.onload (plugin:obsidian-sample-plugin:41677:17)
    at e.load (app.js:1:869278)
    at e.<anonymous> (app.js:1:1072267)
    at app.js:1:235836
    at Object.next (app.js:1:235941)
    at a (app.js:1:234680)

Somehow, the imported classes are undefined.
Any ideas? How can I debug such issues in Obsidian?

Thanks in advance

I searched the keyword “TypeScript” in the repo, and find some related topics.

In conclusion, you can try to import it through this line.
import { DataSet } from "vis-network/standalone"

I also tested it, and it works well to me.

Refer to:

1 Like

Many thanks, I will give it a try