I am trying to familiarize myself with writing Joplin plugins. I have successfully gone through the steps of the "Getting started with plugin development" guide (sorry I only get 1 link as a new user) which creates a working "Hello world" program.
I am now trying to complete the more in-depth tutorial here: "Creating a table of content plugin" and things have gone smoothly until this section Getting the note sections and slugs. Here when I compile (npm run dist) this code (if I use the ampersand symbol it won't let me post, in the code below AT stands for ampersand):
const uslug = require(' AT joplin/fork-uslug');
let slugs = {};
function headerSlug(headerText) {
const s = uslug(headerText);
let num = slugs[s] ? slugs[s] : 1;
const output = [s];
if (num > 1) output.push(num);
slugs[s] = num + 1;
return output.join('-');
}
I get the following error in the command console:
ERROR in ./src/index.ts
Module not found: Error: Can't resolve 'AT joplin/fork-uslug' in 'C:\Joplin\plugin development\Test001\src'
@ ./src/index.ts 76:14-43
If I replace the line "const uslug = require(' AT joplin/fork-uslug');" with "const uslug = joplin.require(' AT joplin/fork-uslug');" the plugin compiles, but when I run it in joplin I get the following error in Joplin's console:
plugin_index.js:61 Uncaught Error: Module not found: AT joplin/fork-uslug
at target (plugin_index.js:61)
at newTarget (C:\Joplin\resources\app.asar\vendor\lib\ AT joplin\lib\services\plugins\sandboxProxy.js:21)
at Object.handler.apply (C:\Joplin\resources\app.asar\vendor\lib\ AT joplin\lib\services\plugins\sandboxProxy.js:35)
at Object.<anonymous> (plugin_ThisIsATestPlugin.js:1)
at n (plugin_ThisIsATestPlugin.js:1)
at plugin_ThisIsATestPlugin.js:1
at plugin_ThisIsATestPlugin.js:1
From googling it looks like there are a few folks having issues with uslug recently but I am a bit out of my depth. I'm not attached to the uslug package really and would be fine proceeding without it. I tried replacing the variable "uslug" with a constant but I'm out of my comfort zone and don't think I used the correct data type -- so that threw more errors.
If anyone knows of a quick fix for these errors let me know. Or if you see a quick way for me to proceed with the tutorial? (Like a suitable constant to replace uslug with?) Much obliged!