0
I am trying to perform the default export of a class in Node.js, but when I try to compile the main.js file a type error is returned:
Syntaxerror: Unexpected Identifier
at new Script (vm.js:84:7)
creatat eScript (vm.js:264:10)
At object.runInThisContext (vm.js:312:10)
At module. _Compile (Internal/modules/cjs/Loader.js:694:28)
At object.Module. _Extensions.. js (Internal/modules/cjs/Loader.js:745:10)
At module.load (Internal/modules/cjs/Loader.js:626:32)
at tryModuleLoad (Internal/modules/cjs/Loader.js:566:12)
At function.Module. _load (Internal/modules/cjs/Loader.js:558:3)
At function.Module.runMain (Internal/modules/cjs/Loader.js:797:12)
at executeUserCode (Internal/bootstrap/Node.js:526:15)
Can anyone tell me why this happens?
//book.js
export default class Book {
constructor(title, author) {
this._title = title;
this._author = author;
}
get title() {
return this._title;
}
set title(title) {
this._title = title;
}
get author() {
return this._author;
}
set author(author) {
this._author = author;
}
printDescription() {
console.log(`The book ${this._title} was written by ${this._author} `);
}
}
//main.js
import Book from "./book.js";
const Book01 = new Book("O nome do vento", "Patrick Rothffus");
Book01.printDescription();
you have tried to export the class using the module.Exports and then using require to import it?
– Pedro Henrique Cndido Ferreira