Not sure about the error but that series might be a bit out of date now - take a look at this one. For custom components I would recommend using Jeffs laravel-elixir-vueify package.
More info on vueify: https://vuejs.org/guide/application.html
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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!
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();
Please or to participate in this conversation.