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

bart's avatar
Level 13

Class is not a Constructor

Hey everybody,

I'm trying to dive into the great world of JS, ES6 and browserify and did follow this tutorial: https://laracasts.com/series/laravel-5-and-the-front-end/episodes/8

I'm using a fresh 5.2 installation of Laravel and create these files:

// resources/js/main.js
var Counter = require('./modules/Counter');
new Counter();

// resources/js/modules/Counter.js
export default class Counter {
    constructor(){
        console.log('init..');
    }
}

// gulpfile.js
mix.browserify('main.js');

But when I load my view that includes the processed main.js file I'm getting: "main.js:5 Uncaught TypeError: Counter is not a constructor"

Do you have any idea what I'm doing wrong here?? Thanks a lot!

0 likes
4 replies
bart's avatar
Level 13

Hey, thanks for your quick answer. It hasn't to do anything with VueJS, so it doesn't feel the right way imo. I'm trying to understand the problem here. Is it an ES6 issue?

d3xt3r's avatar
d3xt3r
Best Answer
Level 29

Well the way you are exporting it should be consistent with the way you import it..

ES6 style

import Counter from './modules/Counter.js';
new Counter();

Using require

var Counter = require('./modules/Counter.js');
new Counter.default();

OR

export class Counter {
    ...
}

var Counter = require('./modules/Counter.js');
new Counter.Counter();

// -- OR --

import {Counter} from './modules/Counter.js'
new Counter();
2 likes
bart's avatar
Level 13

Thanks @d3xt3r! Using import Counter from './modules/Counter.js'; did the trick. Great!

Please or to participate in this conversation.