mitcheljh's avatar

Laravel mix doesn't seem to combine classes into single module

I'm using mix with ES6 classes and modules, and am struggling with getting everything to work as if it were in a single (app.js) module.

From my webpack.mix.js, I'm calling... mix.js('resources/js/public/app.js', '/public/js/app.js') .version() .sourceMaps();

In resources/js/public/app.js, I've got, for a basic example, import (Base } from "./classes/Base", import { Derived } from "/classes/Derived";

The contents of Base is simply, export class Base {

}

The contents of Derived is simply, export class Derived extends Base {

}

Everything compiles fine, and in my main layout, I have

When I load the page, I get the following error: Uncaught ReferenceError: Base is not defined

I was under the impression, that since these two classes are in the same file, they will be in the same module, and I shouldn't have to import them. Am I wrong in this assumption?

Thanks in advance

0 likes
4 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

You need to import Base inside Derived

import {Base} './Base';
export class Derived extends Base {

}
1 like
mitcheljh's avatar

Thanks Sinnbeck, I've done that, and it does work, but I just didn't think that I should need to do that, since both classes are in the same app.js file. Am I wrong in this thinking?

Sinnbeck's avatar

@mitcheljh Yeah you need to import what you need in the files. A bit like you use SomeClass in php

1 like
mitcheljh's avatar

Ahh, thank you!

Still getting a little familiar with ESS6 modules. :)

Please or to participate in this conversation.