How do you load a js library for widgets?

mdjoseph12
Giga Contributor

Trying to import a js library to use with a widget on the service portal, what is the best way to import the library and reference it within the html. I've tried "<script src=.." but it doesn't seem to work 

9 REPLIES 9

Are you getting any errors in the console?

well it appears that its stopping at "Initialization finished. Ready to start", which makes me assume that it's not able to access the quagga functions from the dependency 

Right, I would thing you need to instantiate your Quagga class at some point before using it. Try replacing the line where you set your const, but use var:

var Quagga = require('quagga').default;

Log what that returns and see if that helps.

P.S. There's a barcode widget that comes OOB that you may be able to reference, it's called "Barcode"

Makes sense, and I attempted to use that widget but it didnt seem to work on the service portal. 

 

This is the error that I am recieving after adding that line: 

Uncaught ReferenceError: require is not defined
at HTMLInputElement.eval (eval at globalEval (js_includes_sp_libs.jsx?v=12-03-2019_1915&lp=Tue_Jan_21_06_25_19_PST_2020&c=35_683:185), <anonymous>:97:22)

seems like require() does not exist in the browser/client-side JavaScript