Bundling js files with webpack class undefined

Viewed 1071

Im bundling together the following files contents:

a.js:

class BaseC {
    doIt(){
        console.log(this);
    }
}

class A extends BaseC{
}

b.js:

class B extends BaseC{
}

var b = new B()

b.doIt();

These are bundled in a final app.bundle.js. When running it i get : "Uncaught ReferenceError: BaseC is not defined". This is very odd to me as i can see it as defined first and foremost in the app.bundle.js prior to the rest of the classes as follows:.

var BaseC = function () {
    function BaseC() {
        _classCallCheck(this, BaseC);
    }

    _createClass(BaseC, [{
        key: "doIt",
        value: function doIt() {
            console.log(this);
        }
    }]);

    return BaseC;
}();

Any clues?

P.S: Im not using the require/import system. I know this is how webpack is normally used but what im doing is providing an array with all the js files i want bundled to webpack using the glob module and expected that with such a simple example, it should work.

1 Answers

Try exporting the class from a.js: export class BaseC { ...

and importing it into b.js: import {BaseC} from './a.js' ...

Related