I am trying to do an import from one file to another in VSCode. My two files are as follows:
// file2.js
const Name1 = "Bob";
const Name2 = "Sarah";
class Person {
constructor(name) { this.name = name; }
greet() { console.log('Hello,', this.name); }
}
export {Name1, Name2, Person};
// file1.js
import { Name1, Name2, Person } from "./file2.js"
p = new Person(Name1);
p.greet();
However, I get the following error from VSCode / Node:
import { Name1, Name2, Person } from "./file2.js"
SyntaxError: Cannot use import statement outside a module
What does that mean exactly (why isn't the file considered a module?), and how would I properly fix that to do a valid import?