CustomJS, Node.js and npm add

Hi, I’m getting myself confused and going around in circles so hoping someone can help.

I’m a good enough developer that I know how to cut code, but with new environments such as CustomJS in Obsidian my knowledge is lower than it needs to be.

I find I keep needing to add a node package into CustomJS but none of the require statements work. If I run npm add <package> where will the files go (my past experience is in the subfolder of the code I’m working on - and I don’t want that all in my vault). but if I use npm add -g <package> it installs centrally and is never picked up.

Q1: Is it even possible to add new node packages for CustomJS?

Q2: If so, how?

Q3: If not, how do people work around it?

Thanks in advance, David

From my knowledge CustomJS doesn’t support external npm packages. But its competitor CodeScript Toolkit does.

P.S. I’m the author of CodeScript Toolkit

1 Like

“Competitor”. Them be fightin’ words.

I’ll have a look. Thanks.

@mnaoumov I got CodeScript Toolkit working. Looking to do some image manipulation. I know it’s working because Jimp was accessible - but it doesn’t do webp! Trying to use Sharp instead and it seemed to be partially loading. I couldn’t work out why. Seemed to load some supporting .js files but not all. Should I be trying the async method? It could also have been missing supporting libraries?

@dcb Create an issue in GitHub, attach the problematic vault with scripts and I will take a look

I’ve got a couple of days to play with it. Will see what I can solve myself. Thanks for the offer.

1 Like