function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tim MaysTim Mays 

using Superagent in lwc

Has anyone tried to use Superagent (https://github.com/visionmedia/superagent" target="_blank) in a lightning web component?
import { LightningElement } from 'lwc';
import { loadScript } from 'lightning/platformResourceLoader';
import superagent from '@salesforce/resourceUrl/superagent';

export default class BodaciousDisputatious extends LightningElement {
    superagentInitialized = false;

    renderedCallback() {
        if (this.superagentInitialized) {
            return;
        }

        Promise.all([
          loadScript(this, superagent) // the static resource is not in an archive 
        ]).then(() => {
            this.superagentInitialized = true;
            this.makeTheCall();
        })
    }

    makeTheCall() {
        superagent
        .get ('https://api.idk.com')
        .then((error, response) => {
            if (error) {
                console.error(error);
            }
            if (response) {
                console.warn(response);
            }
        });
    }
}
All I get is get is not a function. Maybe I just have the Friday burnouts, maybe I need to look at it again after some beverages. But incase that dosn't help do any of you fine folks see anything wrong?

This is the js file I used for the static resource named superagent
https://cdn.jsdelivr.net/npm/superagent@5.0.5/dist/superagent.min.js
Best Answer chosen by Tim Mays
Tim MaysTim Mays
After a few tasty drinks and some sleep it was obvious what the issue was. Don't use the namespace of your lib in your import, duh. Use something like...
import superagentResourceUrl from '@salesforce/resourceUrl/superagent';
...
loadScript(this, superagentResourceUrl)
...
superagent.get(...)