ES6/Babel Class constructor cannot be invoked without 'new'

babel class constructor cannot be invoked without 'new'
class constructor activityhandler cannot be invoked without 'new
class constructor spec cannot be invoked without 'new
ts loader class constructor cannot be invoked without 'new
class constructor cannot be invoked without new static method
class constructor datasource cannot be invoked without 'new
class constructor create cannot be invoked without new
class constructor observable cannot be invoked without 'new

I'm trying to create a custom Quill theme, extending the bubble one. I'm facing a strange ES6 inheritance problem, where it seems I cannot call super() in my constructor. Here is my code:

import BubbleTheme, { BubbleTooltip } from 'quill/themes/bubble'

class LoopTheme extends BubbleTheme {
  constructor (quill, options) {
    super(quill, options)
  }

  extendToolbar (toolbar) {
    super.extendToolbar(toolbar)
    this.tooltip = new LoopTooltip(this.quill, this.options.bounds);
    this.tooltip.root.appendChild(toolbar.container);
  }
}

class LoopTooltip extends BubbleTooltip {

}

LoopTooltip.TEMPLATE = [
  '<span class="ql-tooltip-arrow"></span>',
  '<div class="ql-tooltip-editor">',
    '<input type="text" data-formula="e=mc^2" data-link="https://myurl.com" data-video="Embed URL">',
    '<a class="ql-close"></a>',
  '</div>'
].join('');

export { LoopTooltip, LoopTheme as default }

Bubble theme could be found here

My Babel presets:

{
    "presets": [
        "es2015",
        "es2016",
        "stage-0",
        "react"
    ]
}

Webpack js file config:

  module: {
    rules: [
      {
        test: /\.js$/,
        include: [
          resolve(__dirname, 'app')
        ],
        loader: 'babel-loader',
        exclude: /node_modules/
      }, {...

Output generated code:

var LoopTheme = function (_BubbleTheme) {
  _inherits(LoopTheme, _BubbleTheme);

  function LoopTheme() {
    _classCallCheck(this, LoopTheme);

    return _possibleConstructorReturn(this, (LoopTheme.__proto__ || Object.getPrototypeOf(LoopTheme)).apply(this, arguments));
  }

  _createClass(LoopTheme, [{
    key: 'extendToolbar',
    value: function extendToolbar(toolbar) {
      _get(LoopTheme.prototype.__proto__ || Object.getPrototypeOf(LoopTheme.prototype), 'extendToolbar', this).call(this, toolbar);
      this.tooltip = new LoopTooltip(this.quill, this.options.bounds);
      this.tooltip.root.appendChild(toolbar.container);
    }
  }]);

  return LoopTheme;
}(_bubble2.default);

var LoopTooltip = function (_BubbleTooltip) {
  _inherits(LoopTooltip, _BubbleTooltip);

  function LoopTooltip() {
    _classCallCheck(this, LoopTooltip);

    return _possibleConstructorReturn(this, (LoopTooltip.__proto__ || Object.getPrototypeOf(LoopTooltip)).apply(this, arguments));
  }

  return LoopTooltip;
}(_bubble.BubbleTooltip);

LoopTooltip.TEMPLATE = ['<span class="ql-tooltip-arrow"></span>', '<div class="ql-tooltip-editor">', '<input type="text" data-formula="e=mc^2" data-link="myurl.com" data-video="Embed URL">', '<a class="ql-close"></a>', '</div>'].join('');

exports.LoopTooltip = LoopTooltip;
exports.default = LoopTheme;

I'm having the following error: events.js:59 Uncaught TypeError: Class constructor BubbleTheme cannot be invoked without 'new'. However, the LoopTheme is correctly called with new by Quill here. When I debug step by step, I correctly enter the LoopTheme constructor, and the error is raised when super is called.

Am I missing something here? I've always used inheritance, and I use it elsewhere in my code (between my classes), where here am I having trouble?

Thanks for your help

I ran into the exact same issue while extending Quill’s BaseTheme.

As Bergi correctly pointed out in the comments above, this has to do with the fact that babel-loader isn’t transpiling Quill’s modules because they're inside node_modules/, which is excluded.

You can either update the exclude option in your Webpack config and use a regex to skip the node_modules/quill/ folder or use include instead:

{
  test: /\.js$/,
  loader: 'babel-loader',
  include: [
    path.join(__dirname, '../src'), // + any other paths that need to be transpiled
    /\/node_modules\/quill/,
  ]
}

TypeError: Class constructor Person cannot be invoked without 'new , TypeError: Class constructor Person cannot be invoked without 'new' so then Babel will not transform the ES6 classes in your own code and  I can access the injected property test2 inside the constructor. The problem is: ES6 classes does not allow this kind of instantiation. The 'this' property does not exists before the new command is called (and the object created) So, if I want to make it work for ES6 classes, I have to change the above example to:

You can also replace this:

import BubbleTheme from 'quill/themes/bubble'

into this:

const BubbleTheme = Quill.import('themes/bubble')

How to fix this:Error in mounted hook: "TypeError: Class constructor , This happens if Nested is transformed by babel but Base isn't. superclass constructor is not allowed by the ES6 spec -- it's just how babel emulates it in ES5​, Class constructor Model cannot be invoked without 'new' #388. How to Fix the ES6 `class` keyword. for ES7 is that you’d add a “call handler” to the class for when it is invoked without `new`: refers to the new instance in a class constructor.

I would like to suggest another way. In case you are not building quill in you pipe line, you could very well reference the runtime constructor above the extended class.

    import { sanitize } from 'quill/formats/link';

    let BlockEmbed = window['Quill'].import('blots/block/embed');

    export class MediaBlot extends BlockEmbed {
        ...
    }

TypeError: Class constructor model cannot be invoked without 'new , Bug Report Current Behavior i have a trouble using babel , and TypeError: Class constructor model cannot be invoked without 'new' but the sequelize modules are transpiled to es5, (have you see any es6 expression ) Update: the original problem, message saying **TypeError: Class constructor Lexer cannot be invoked without 'new' ** is caused by a mismatch between the code generation target we used for building the antlr4ts runtime (which was es2015) and occurs when its called from code transpiled using the default target (which is es5).

Class constructor DataSource cannot be invoked without 'new' using , Class constructor DataSource cannot be invoked without 'new' using Babel #​2216. Closed. vaskaloidis opened this issue on Jan 23, 2019 · 10 comments. Class constructors can’t be function-called. This protects against forgetting to invoke constructors with new. Also, a class constructor’s prototype property can’t be reassigned. This may

TypeError: Class constructor Component cannot be invoked without , TypeError: Class constructor Component cannot be invoked without is happening, because Babel's preset-es2015 transpiles ES6 classes. Just like many of the other features that are new to ES2015 classes merely provide clean code and syntactic sugar on top of concepts that already exist. We can define a class using the new class keyword. In the class definition we can specifically define a constructor method as well as other instance methods and getters and setters for properties.

Typescript: `TypeError: Class constructor cannot be invoked without , Typescript: `TypeError: Class constructor cannot be invoked without is because I'm using a library that requires targeting es6 , which is fine, fix that I understand is a hack as next/babel is already performing this operation. Even if you have class properties enabled, there might be times when you would want to base the initial state on props, and that would require use of a constructor. Also, normally you'd bind callback methods in a constructor., but if you're using class properties, you can define methods as arrow functions instead.

Comments
  • And where exactly these classes are used? Consider providing stackoverflow.com/help/mcve . A plunk that can replicate the issue would help.
  • Please post here presets you're using. Mb complied code would be useful as well. Is this super(quill, options) line 19?
  • Hi there, indeed, I added my babel presets and the output generated code. Would you need something more? I may try to add a jsbin/fiddle example? cc @estus
  • Is BubbleTheme transpiled as well?
  • Posting a plunk/fiddle or a repo that can replicate the problem will increase the chances to solve the problem.
  • Do you have any ideas to have the same behavior with angular-cli ?
  • Thanks Raphael that was that! Next problem is now svg assets required in ui/icons.. do you have a specific webpack loader need for that ones ? I tried to include them to my already existing ones but without any luck. Thanks
  • Yeah, you need to pass them through html-loader. The following lines worked for me: gist.github.com/raphaelsaunier/5e296aad093cdc5035827660f95b42bf
  • @raphaelsaunier thanks a bunch. I also found the Quill documentation explaining how to integrate it into your webpack assets pipeline. Your answer + that worked like a charm! Merci :)
  • Thank you x1000! Worked for me.