Sharing a third party library

467
3
05-20-2024 11:04 PM
PartyPelican
New Contributor III

Does anyone know how we should be sharing third party libraries across multiple widgets?

I have read some documentation and seen examples, but I'm not quite sure I grasp the concept yet. For example, if I'd like to use react query across multiple widgets, do I install it in the client folder? I've seen esri's d3 example, where they copied the library to the runtime folder of the widget, but can we not just import the module that's installed in the client folder node_modules? Would I need to copy the library to every widget I want to use it in? 

 

I appreciate anyone's insight.

3 Replies
JeffreyThompson2
MVP Regular Contributor

https://developers.arcgis.com/experience-builder/guide/share-code-between-widgets/

Experience Builder 1.14 has the shared code feature. I believe you could save the library in a shared folder, so it only needs to be downloaded once.

GIS Developer
City of Arlington, Texas
PartyPelican
New Contributor III

I gave this a try. 

I created a shared-code folder in the widgets directory. Then I ran npm init and npm install to install react query in the shared-code folder. I created a index.js file that imports the react query library and exports it. 

Then in my custom widget, I imported the library from that shared-code index.js file. My IDE recognizes the library, but the browser console shows a Load Module Error.

Do you know what I might be doing wrong?

JeffreyThompson2
MVP Regular Contributor

👻I don't know. I'm usually just making stuff up. I throw out an idea, somebody tries it, then I know if it works.

GIS Developer
City of Arlington, Texas
0 Kudos