How to properly install an external library for Plugin development?

Dear all,
I’m trying to develop a plugin for Obsidian. I’m new to Typescript so kindly bear with me if my questions are too fundamental. The plugin I want to build is an automatic keyword extractor. So I would like to input some text and get relevant tags for that input text.
I have found a library that does just this. I’m not able to load this library properly.

What I have done till now

  • I run the following command to install the package in the root of my plugin folder
    npm i rake-js

I ran it again to grab a screen shot and I got the following

  • Then I import the rake library in the main.ts like this import rake from 'rake-js'

  • Then I run npm run dev. I get the following error
    (!) Plugin typescript: @rollup/plugin-typescript TS1192: Module '"/Users/myName/Library/Mobile Documents/com~apple~CloudDocs/MyVaultName/.obsidian/plugins/auto-tagger-obsidian/rake-js"' has no default export.

  • What am I doing wrong? Any help is appreciated. Feel free to ask for more details :slight_smile:

I am not super familiar with typescript but you either need to see if there is a @types/rake-js npm module, or you need to create your own rake-js.d.ts module declaration. But typescript is not required if you feel more comfortable in vanilla JS. You can remove the typescript plugins for rollup, and do some renaming of files and develop your plugin without it. If you use VS Code it can still show you the obsidian type declarations on command click, and will still give you decent type ahead support.

The only hard rule is that your `main.js bundle contain all the code required to run your plugin, how you get there is up to you.

1 Like

Check if you need to enable allowSyntheticDefaultImports https://www.typescriptlang.org/tsconfig#allowSyntheticDefaultImports

To elaborate on @shichongrui second option “you need to create your own module”, here’s what works for me:

Create a new file and declare those modules as follows: