Getting an error when reactively updating a component #5

Closed
opened 2020-12-23 09:52:16 +01:00 by Ghost · 2 comments

Hi, thanks for the great plugin, it works great, but only on the first page load.

I'm trying to use it together with nuxt, put the code for getting photos in asyncData and everything works on the first page load, but when I go to another page I get the error

error => TypeError: The "listener" argument must be of type Function. Received type object
    at checkListener (events.js?faa1:72)
    at _addListener (events.js?faa1:169)
    at module.exports.addListener (events.js?faa1:227)
    at Object.http.request (index.js?9490:38)
    at Object.get (index.js?9490:43)
    at Object.https.get (index.js?24f8:17)
    at eval (index.js?61a9:25)
    at new Promise (<anonymous>)
    at Object.get (index.js?61a9:22)
    at eval (index.js?61a9:79)

here is my code

    async asyncData({ $axios, params, store, redirect }) {  
        let hashtag = null;
        try {
            const Insta = require("scraper-instagram");
            const InstaClient = new Insta();
            const yourSessionId = "my_session_id_from_cookie";
            const client = await InstaClient.authBySessionId(yourSessionId);
            hashtag = await InstaClient.getHashtag("some_hashtag");
        } catch (error) {
            console.log(`error =>`, error);
        }

        const data = {
            hashtag: hashtag,           
        };
        return data;
    },

after digging i found some strange, you use http.request wich get two arguments,

http.request = function (opts, cb) {}

but you pass three arguments url, headers, and callback

https.get(url, {
    headers: {
    	cookie: sessionId ? `sessionid=${sessionId}` : ''
    }
    }, res => {
    ...
    }
);

for some reason, headerss get into the callback

Hi, thanks for the great plugin, it works great, but only on the first page load. I'm trying to use it together with nuxt, put the code for getting photos in asyncData and everything works on the first page load, but when I go to another page I get the error ``` error => TypeError: The "listener" argument must be of type Function. Received type object at checkListener (events.js?faa1:72) at _addListener (events.js?faa1:169) at module.exports.addListener (events.js?faa1:227) at Object.http.request (index.js?9490:38) at Object.get (index.js?9490:43) at Object.https.get (index.js?24f8:17) at eval (index.js?61a9:25) at new Promise (<anonymous>) at Object.get (index.js?61a9:22) at eval (index.js?61a9:79) ``` here is my code ``` async asyncData({ $axios, params, store, redirect }) { let hashtag = null; try { const Insta = require("scraper-instagram"); const InstaClient = new Insta(); const yourSessionId = "my_session_id_from_cookie"; const client = await InstaClient.authBySessionId(yourSessionId); hashtag = await InstaClient.getHashtag("some_hashtag"); } catch (error) { console.log(`error =>`, error); } const data = { hashtag: hashtag, }; return data; }, ``` after digging i found some strange, you use http.request wich get two arguments, `http.request = function (opts, cb) {}` but you pass three arguments url, headers, and callback ``` https.get(url, { headers: { cookie: sessionId ? `sessionid=${sessionId}` : '' } }, res => { ... } ); ``` for some reason, headerss get into the callback

Hello,

Yes, the method can take two arguments options and callback, but it can also take three arguments url, options and callback, which I'm actually doing, see the documentation.

Apparently, the error you're experiencing can happen when when using on mehods (from EventEmitter), which is strange because the three listeners I use (data, end and error) are indeed called with a function as second argument.

Although, I'll continue investigating. In the meantime, do you think you could reproduce this bug outside of any framework so I can better understand it ?

Thanks.

Hello, Yes, the method can take two arguments `options` and `callback`, but it can also take three arguments `url`, `options` and `callback`, which I'm actually doing, see the [documentation](https://nodejs.org/api/https.html#https_https_get_options_callback). Apparently, the error you're experiencing can happen when when using `on` mehods (from `EventEmitter`), which is strange because the three listeners I use (`data`, `end` and `error`) are indeed called with a function as second argument. Although, I'll continue investigating. In the meantime, do you think you could reproduce this bug outside of any framework so I can better understand it ? Thanks.

Closing due to inactivity.

Closing due to inactivity.
This repo is archived. You cannot comment on issues.
No Milestone
No Assignees
2 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: KaKi87/scraper-instagram-v1#5
There is no content yet.