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

KEEP GETTING TypeError: The "listener" argument must be of type Function. Received type object #96

Closed
ghost opened this issue Oct 13, 2021 · 4 comments

Comments

@ghost
Copy link

ghost commented Oct 13, 2021

Here is the code that I have written:
`const client = new TwitterApi({
appKey: API_KEY,
appSecret: API_KEY_SECRET,
accessToken: ACCESS_TOKEN,
accessSecret: ACCESS_TOKEN_SECRET,
})
// const client = new TwitterApi(BEARER_TOKEN);

async function makeTweet() {
const createdTweet = await client.v1.tweet('twitter-api-v2 is awesome!')
console.log('Tweet', createdTweet.id_str, ':', createdTweet.full_text)
}
`

Is the API broken or am I making a mistake somewhere? Thanks

@alkihis
Copy link
Collaborator

alkihis commented Oct 13, 2021

Hi,

This is a duplicate of #94.
As specified in this issue, giving URL and options separately has been added in Node 10.9.

Either you're using an old version of Node.js, either there's a dependency that modifying native agent-base/patch-core.js as discussed in this comment: #94 (comment).

Check that, then tells me if your problem is still here :)

@alkihis
Copy link
Collaborator

alkihis commented Oct 13, 2021

Re,
It seems that agent-base dropped https.request patching since 5.0.0 (two years ago): TooTallNate/node-agent-base#38 (comment).

Please check your (sub)dependencies, and update them.

@ghost
Copy link
Author

ghost commented Oct 14, 2021

I'm using react and after reinstalling node the problem still persists.
Here is my stacktrace:
Unhandled Rejection (TypeError): The "listener" argument must be of type Function. Received type object

checkListener
node_modules/events/events.js:72
_addListener
node_modules/events/events.js:169
push../node_modules/stream-http/lib/request.js.module.exports.addListener
node_modules/events/events.js:227
push../node_modules/stream-http/index.js.http.request
node_modules/stream-http/index.js:37
push../node_modules/https-browserify/index.js.https.request
node_modules/https-browserify/index.js:12
RequestHandlerHelper.buildRequest
node_modules/twitter-api-v2/dist/client-mixins/request-handler.helper.js:158
RequestHandlerHelper.makeRequest
node_modules/twitter-api-v2/dist/client-mixins/request-handler.helper.js:161
TwitterApiv1.send
node_modules/twitter-api-v2/dist/client-mixins/request-maker.mixin.js:31
TwitterApiv1.post
node_modules/twitter-api-v2/dist/client.base.js:142
TwitterApiv1.tweet
node_modules/twitter-api-v2/dist/v1/client.v1.write.js:56
makeTweet
src/App.js:31

`async function makeTweet() {
   const createdTweet = await client.v1.tweet('twitter-api-v2 is awesome!')
   console.log('Tweet', createdTweet.id_str, ':', createdTweet.full_text)
}`

HTMLUnknownElement.callCallback
node_modules/react-dom/cjs/react-dom.development.js:3945
invokeGuardedCallbackDev
node_modules/react-dom/cjs/react-dom.development.js:3994
invokeGuardedCallback
node_modules/react-dom/cjs/react-dom.development.js:4056
invokeGuardedCallbackAndCatchFirstError
node_modules/react-dom/cjs/react-dom.development.js:4070
executeDispatch
node_modules/react-dom/cjs/react-dom.development.js:8243
processDispatchQueueItemsInOrder
node_modules/react-dom/cjs/react-dom.development.js:8275
processDispatchQueue
node_modules/react-dom/cjs/react-dom.development.js:8288
dispatchEventsForPlugins
node_modules/react-dom/cjs/react-dom.development.js:8299
(anonymous function)
node_modules/react-dom/cjs/react-dom.development.js:8508
batchedEventUpdates$1
node_modules/react-dom/cjs/react-dom.development.js:22396
batchedEventUpdates
node_modules/react-dom/cjs/react-dom.development.js:3745
dispatchEventForPluginEventSystem
node_modules/react-dom/cjs/react-dom.development.js:8507
attemptToDispatchEvent
node_modules/react-dom/cjs/react-dom.development.js:6005
dispatchEvent
node_modules/react-dom/cjs/react-dom.development.js:5924
unstable_runWithPriority
node_modules/scheduler/cjs/scheduler.development.js:468
runWithPriority$1
node_modules/react-dom/cjs/react-dom.development.js:11276
discreteUpdates$1
node_modules/react-dom/cjs/react-dom.development.js:22413
discreteUpdates
node_modules/react-dom/cjs/react-dom.development.js:3756
dispatchDiscreteEvent
node_modules/react-dom/cjs/react-dom.development.js:5889

@alkihis
Copy link
Collaborator

alkihis commented Oct 14, 2021

In your stack trace, you seems to use https-browserify, a package that hasn't been updated since 5 years (!), providing front-end https module.

Please also note that this package is meant to be used on back-end side, not front-end.
In almost every scenario, given consumer keys/bearer tokens to front-end side of your app is definitively not a good idea.
If you're using React in a SSR scenario (like with Next framework), it's okay, but otherwise consider migrating your Twitter logic to a back-end Node.js server.

As I said in my previous message, your Node version or/and your dependencies are out-of-date.

This is not a problem of this lib and we shall not consider applying patches that only serves to allows usage with outdated Node & dependencies.
You will get this problem with every lib that uses https.request(url, options).

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

1 participant