I have got this node server and a bunch of JS classes in my js directory. I want to create a file called "exports.js" that exports all the classes required by server (using exports.Classname = class notation). However, the problem is that exports.js doesn't have access to the classes. I was wondering what's the correct syntax for importing the whole ES6 class in another file. So far I have tried following with no luck:
//I want to import User class from User.js
import "./User.js";
import "User";
import "./User";
Any help would be much appreciated.
Note: Not that it makes any difference but please note that I am using Babel transpiler.
I have got this node server and a bunch of JS classes in my js directory. I want to create a file called "exports.js" that exports all the classes required by server (using exports.Classname = class notation). However, the problem is that exports.js doesn't have access to the classes. I was wondering what's the correct syntax for importing the whole ES6 class in another file. So far I have tried following with no luck:
//I want to import User class from User.js
import "./User.js";
import "User";
import "./User";
Any help would be much appreciated.
Note: Not that it makes any difference but please note that I am using Babel transpiler.
Share Improve this question edited Dec 17, 2016 at 0:28 fur866 asked Dec 17, 2016 at 0:23 fur866fur866 4132 gold badges5 silver badges14 bronze badges 5 |1 Answer
Reset to default 18// user.js
class user{
...
}
export default user
// another js
import user from './user.js'
import
is fine. If not, you have to userequire()
. Babel transformsimport
inrequire()
– user2345 Commented Dec 17, 2016 at 0:35export default [YOUR CLASS]
in the file your defineUser
. – newguy Commented Dec 17, 2016 at 5:03import User from './User'
, then you can reference it – Ovidiu Dolha Commented Dec 19, 2016 at 8:14