10 months ago

ES6 Class does not work in compiled js

Posted 10 months ago by ahsan


i have this class in my /src/js/main.js

class Point {
    constructor(x, y) {
        this.x = x;
        this.y = y;

    toString() {
        return `(${this.x}, ${this.y})`;

export default Point;

here is the webpack.mix.js file

let mix = require('laravel-mix')

mix.js('src/js/main.js', 'dist/')

so when i include in my index.html file like this:

<!DOCTYPE html>
    <title>es6 test</title>

    <!-- Scripts -->
    <script src="dist/main.js"></script>

    <script type="text/javascript">
        new Point(1, 3)

so i have this error in console

"Uncaught ReferenceError: Point is not defined"

Actually, i want to create npm package for users to just include my script and instantiate the script

like this

new Point(1, 3)

is there any solution?


Please sign in or create an account to participate in this conversation.