primero.js :
export function multiply() { return 2 * 3; }segundo.js :
import { multiply } from './first.js'; /* const {multiply} = require('./first.js'); */ const result = multiply(); console.log(`Result: ${result}`);Cuando lo ejecuto, obtengo
SyntaxError: Unexpected token {error.
Si trato de activar solo la línea de importación require , obtengo
SyntaxError: Unexpected token exporterror.
Archivos actualizados que funcionan. Se agregó module.exports a math.js y use require en main.js :
matemáticas.js :
function hello() { console.log("hello"); } module.exports = { hello }principal.js
const {hello} = require('./math.js'); hello();