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.

class constructors must be invoked with |new|

See original GitHub issue

Trying to implement base functionality on our existing React app.

Getting

class constructors must be invoked with |new|

for any component I add the static property to.

It looks like this is a common issue across this library and the predecessors, but I was under the impression this library had it solved, so I must be missing something.

I’ve attached the library via NPM as well as manually adding the src to see if I could narrow it down. Best I can tell the error is thrown here (line 505): _this = _possibleConstructorReturn(this, _getPrototypeOf(WDYRPatchedClassComponent).call(this, props, context));

Excluding markup, my component looks like this: `class Home extends React.Component {

constructor(props) { super(props); } static whyDidYouRender = true; render(){ … } export default Home; `

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:29

github_iconTop GitHub Comments

7reactions
frederikhorscommented, Apr 26, 2019

Same error here using the create-react-app 3 and this import:

const whyDidYouRender = require('@welldone-software/why-did-you-render/dist/no-classes-transpile/umd/whyDidYouRender.min.js').

My browserlist:

  "browserslist": {
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }

Maybe you should re-open this issue.

5reactions
vzaidmancommented, Jan 19, 2019

fixed in v2.5.0.

If you are not transpiling your classes, the library should be built without class transpilations as well.

So we added 3 endpoints where it is indeed not transpiled:

  "main-no-classes-transpile": "dist/no-classes-transpile/cjs/whyDidYouRender.min.js",
  "module-no-classes-transpile": "dist/no-classes-transpile/esm/whyDidYouRender.min.js",
  "browser-no-classes-transpile": "dist/no-classes-transpile/umd/whyDidYouRender.min.js",

to use it, import the library like this:

const whyDidYouRender = require('@welldone-software/why-did-you-render/dist/no-classes-transpile/umd/whyDidYouRender.min.js');
Read more comments on GitHub >

github_iconTop Results From Across the Web

class constructors must be invoked with 'new' error in React ...
So I'm trying to use react native and aws-amplify to build a web and mobile app with one code base. ... So after...
Read more >
Uncaught TypeError: class constructors must be invoked with ...
The animations using older loaders (SEA3D for example) don't work in the current beta. They worked just fine in r126.
Read more >
Class constructor cannot be invoked without 'new' in JS
Class constructor cannot be invoked without 'new' in JS # · Creates a new object that inherits the prototype of the class. ·...
Read more >
class constructors must be invoked with 'new' - three.js forum
I'm getting this issue when using SVGLoader.js AND other sub libraries. i get the message : "“class constructors must be invoked with 'new'”....
Read more >
constructor - JavaScript - MDN Web Docs - Mozilla
The constructor method is a special method of a class for creating and initializing an object instance of that class.
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 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