Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ScottIsAFool opened this issue May 9, 2020 · 5 comments
Open

Comments

@ScottIsAFool
Copy link

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
Copy link
Author

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.

@ryhinchey
Copy link
Contributor

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

@ScottIsAFool
Copy link
Author

ScottIsAFool commented May 9, 2020

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?

@donavon
Copy link
Owner

donavon commented May 14, 2020

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;

@ScottIsAFool
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants