Estou tentando realizar o export default de uma classe em node.js, mas quando tento compilar o arquivo main.js é retornado um erro do tipo:
SyntaxError: Unexpected identifier
at new Script (vm.js:84:7)
at createScript (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)
Alguém sabe me dizer por que isso acontece?
//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();