Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mbagentur's avatar

.default is not a constructor with ES2015 Import, Export, browserify and class

Hi - short question for you.

  • In my Mouse.js I export a class "Mouse".
export class Mouse {
    constructor(options){
        let defaultOptions = {
            dragLength: 0,
        };
        this.options = mergeObjects(defaultOptions,options);

        this._startX = 0;
        this._x = 0;
        this._isDown = false;
        this._isDragging = false;
    }

    isBetween(left, right){
        return (this._x >= left) && (right >= this._x);
    }
}
  • In my Schedule.js I import this class with import Mouse from './Mouse'; I then use it like this:
class Schedule {
   constructor(options) {
   this.options = options;
   this.mouse = new Mouse();
 }
...
}
  • I get the following error:

Schedule.js: Uncaught TypeError: _Mouse2.default is not a constructor

Any idea guys? Thank you very much!

0 likes
2 replies
JeffreyWay's avatar
Level 59

Try:

export default class Mouse {

Or:

class Mouse {}

export default Mouse;
1 like
mbagentur's avatar

That worked - thank you. As I understand it, you can just have one default export in a module per file!? What if I need to / want to export multiple classes/(methods?) per file? The default-solution won't work anymore, right?

Please or to participate in this conversation.