3

I've been sitting here for 3 hours straight, trying to figure out how I could possibly export a class from one file, require it (multiple times) in other files, so that that class can be extended.

My current code looks something like this:

// base.js //
class Base {
    constructor() { ... }
}

exports = Base;

// extension.js //
var Base = require('./base.js');

class Extension extends Base {
    constructor() { ... }
}

I get an Exception telling me that 'Base' is not a constructor. When I run console.log(Base), I get an empty object. Am I doing something completely wrong, or is my desire not possible?

I'd be glad for any help given!

Qrakhen
  • 91
  • 7
  • 1
    Why don't you do `module.exports = Base;`? And if you're using ES6, why not `export default Base;`? – Andrew Li Feb 18 '17 at 04:36
  • This is so embarrasing. How I missed the module.* there is completely unclear to me. Thank you so much, I'm gonna cry in agony now. – Qrakhen Feb 18 '17 at 04:57

1 Answers1

1

Node doesn't support normal ES6 exporting yet. So module.exports is required as said in the comments.

Janne
  • 1,665
  • 15
  • 22