question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting "TypeError: undefined is not a constructor (evaluating 'new url_1.URL)"

See original GitHub issue

Prerequisites

  • [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}`)')`.

2021-04-14 at 12 15

Steps to Reproduce

  1. 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);
  1. 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:closed
  • Created 2 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
HunterLarcocommented, Apr 20, 2021

@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 =)

1reaction
spidgornycommented, Apr 19, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found