first.js:
export function multiply() {
return 2 * 3;
}
second.js:
import { multiply } from './first.js';
/*
const {multiply} = require('./first.js');
*/
const result = multiply();
console.log(`Result: ${result}`);
When I run it, I get
SyntaxError: Unexpected token {
error.
If I try to only active the require import line, I get
SyntaxError: Unexpected token export
error.
Updated files that work. Added module.exports to math.js and use require in main.js:
math.js:
function hello() {
console.log("hello");
}
module.exports = {
hello
}
main.js
const {hello} = require('./math.js');
hello();