Problem with es6 classes in separate files inside a package


#1

i have a problem: when trying to create my own meteor package and creating es6 classes (one class per file), somehow i don’t get it working because ether problem of that parent classes are not defined or a very strange “TypeError: Super expression must either be null or a function, not undefined”, BUT classes in one file are working with extends and super call…

class Parent
{
constructor()
{
}
}
class Child extends Parent
{
constructor()
{
super();
}
}

this simple code doesn’t work…

when inside a meteor package in separated files
(with and without export definition)


#2

class Parent {} equates to var Parent = Parent {}, so is always (in Meteor) file scoped. One workaround is to make it global (package scoped): Parent = class Parent {}


#3

thank you very much :

i didn’t really expected that being the same for this new class definitions, is there a reason defining classes only for the local file?


#4

I’ve found that I’ve had to do this in client side code to make things work:
“use strict”;

window.Route = class {};

If I remove window I get an error message saying Route is undefined. Any ideas why? And is it correct to use window to solve my problem?


#5

This blog entry explains what is happening. Also gives a solution.

http://blog.east5th.co/2015/09/23/exporting-es6-classes-from-meteor-packages/


#6

It doesn’t give the solution to my problem. The solution was to add the ecmascript package. Once added you can remove window and you can also remove "use strict";.