donavon/thwack

"Thwack: Invalid options object during request." on simple GET

Opened this issue · 5 comments

When performing a simple GET call, I'm getting the following error message

"Thwack: Invalid options object during request. Check your event callbacks."

Code looks like this:

import thwack from 'thwack';

const app = async () => {
    try {
        const w = await thwack.get("https://github.com");
        let e = 1;
    }
    catch (er) {
        let o = 1;
    }

    let i = 1;
}

app();

Repro project can be downloaded here: thwack-test.zip

I suspect this is because I'm trying to use this in an npm module myself and I'm running it through a terminal window.

https://github.com/donavon/thwack/blob/master/src/default/index.js#L4-L6

This code would seem to suggest that you're only catering for this being used in a browser, given it's the lack of fetch that causes that specific error.

Search the readme for nodejs. If you’re trying to use this in node, you must import it like import thwack from 'thwack/node'; (if using node 12+))

you must import it like import thwack from 'thwack/node';

Unfortunately that doesn't work if you are using Typescript. I end up with an import error. Same applies if I were to use thwack/core as well.

Also, and this might be a noob question, if I do end up changing it to use thwack/node, how will that affect anyone who may import my module?

You can always set fetch yourself. If you look at thwack/node you'll see that it requires node-fetch. You could do the same.

import thwack from 'thwack';
import fetch from 'node-fetch';
thwack.defaults.fetch = fetch;

That gives me an error saying:
image

I had tried this before using the ThwackOptions.fetch which I think might have given the same issue.