Getting "TypeError: undefined is not a constructor (evaluating 'new url_1.URL)"
See original GitHub issuePrerequisites
- [x ] Put an X between the brackets on this line if you have done all of the
following:
- Checked that your issue isn’t already filed: [open issues]
- Checked the [bug report guidelines]
Description
Trying to run the readme example, it is throwing error Unhandled Promise Rejection: TypeError: undefined is not a constructor (evaluating 'new url_1.URL(
https://api.twitter.com/2/${endpoint}`)')`.
Steps to Reproduce
- Init Twitter v2 and try to console log data as below
const Twitter = require('twitter-v2');
const client = new Twitter({
consumer_key: '',
consumer_secret: '',
access_token_key: '',
access_token_secret: '',
});
const { data } = await client.get('tweets', { ids: '1228393702244134912' });
console.log(data);
- This will throw the error mentioned above and shown in the screenshot
Expected behavior:
It should console the response
Actual behavior:
It throws error as shown in the above screenshot
Reproduces how often:
All the time
1.1.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
TypeError: undefined is not a constructor - Stack Overflow
I was getting TypeError: undefined is not a constructor error using the includes() method. The includes() and endsWith() methods are new in ...
Read more >27/33 Loop the loop error TypeError: 'undefined' is not a ...
I keep getting the error "TypeError: 'undefined' is not a constructor." I have tried changing the `family[i].name` and `family[i].age` in the `console.log` ...
Read more >TypeError:undefined is not a constructor (cordova - iOS)
Hello All,. I have an issue to display google map with multiple marker. When I use, var baseArrayClass = new plugin.google.maps.BaseArrayClass(data_array);
Read more >Intl: ListFormat undefined is not a constructor
TypeError : undefined is not a constructor (evaluating 'new Intl.ListFormat(navigator.language, listFormatOptions)'). This works fine on Safari.
Read more >Resolving the JavaScript Promise Error "TypeError: Cannot ...
TypeError - Cannot read property 'then' of undefined is thrown when the caller is expecting a Promise to be returned and instead receives ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@spidgorny is correct. This library is not intended for use in the browser (and generally it’s not a great idea to leak your secrets in the browser). I’d suggest running a thin server between twitter and your client to handle twitter api requests.
Unfortunately I’m not familiar with Next.js so I’ll have to leave help with that to the community =)
It would be rather bad to make your twitter secret keys accessible in the browser. I also use next.js - all my Twitter API is done in /pages/api/ routes. Besides, I don’t think it was ever supposed to work directly in the browser.