thwack icon indicating copy to clipboard operation
thwack copied to clipboard

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

Open ScottIsAFool opened this issue 4 years ago • 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

ScottIsAFool avatar May 09 '20 08:05 ScottIsAFool

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.

ScottIsAFool avatar May 09 '20 09:05 ScottIsAFool

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+))

ryhinchey avatar May 09 '20 13:05 ryhinchey

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?

ScottIsAFool avatar May 09 '20 14:05 ScottIsAFool

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;

donavon avatar May 14 '20 05:05 donavon

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.

ScottIsAFool avatar May 14 '20 13:05 ScottIsAFool