Twitter Client Test Error
serdarkaracay opened this issue · 2 comments
serdarkaracay commented
Very quick start test
twitterApi.js
import TwitterClient from "twitter-api-client";
//const TwitterClient = require("twitter-api-client");
const twitterApi = new TwitterClient({
apiKey: "xxxx",
apiSecret: "xxx",
accessToken: "xxxx",
accessTokenSecret: "xxxx",
ttl: 120, // seconds. Defaults to 360
disableCache: true, // Disables the caching behavior. Defaults to 'false'
maxByteSize: 32000000, // Maximum (approximated) memory size for cache store. Defaults to 16000000.
});
const data = await twitterClient.accountsAndUsers.usersSearch({ q: 'twitterDev' });
node run command
node --experimental-modules twitterApi.js
Errors
TypeError: TwitterClient is not a constructor
const data = await twitterClient.accountsAndUsers.usersSearch({ q: 'twitterDev' });
^^^^^ SyntaxError: Unexpected reserved word
Can you please add a simple test start code?
SimonHoiberg commented
Hi @serdarkaracay
Thanks for creating this issue.
Yes, when you are using the require
syntax, you are importing the entire module.
You need to use the default export, which is the class (constructor function).
const TwitterClient = require("twitter-api-client").default;
wobsoriano commented
Using node v14.3.0 with require syntax, but still getting a not constructor error when adding .default
.
Instead of this
const TwitterClient = require('twitter-api-client').default;
I have to do this
const TwitterClient = require('twitter-api-client').TwitterClient;