Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

195
Views
Importe un archivo JS a otro en JS simple

Así que imaginemos que tengo dos scripts js

script1.js

 export default function Hello() { return "Hello buddy!"; }

script2.js

 import { Hello } from './script1.js'; function print(){ let val = Hello; console.log(val); }

Cuando ejecuto la función de impresión en el navegador, aparece el siguiente error

 Uncaught SyntaxError: Cannot use import statement outside a module Unexpected token 'export'

Investigué un poco y esto se resolvió agregando un módulo de tipo a script2.js. Pero la pregunta es. No tengo un HTML para cambiar el script. Hago todo en vainilla javascript. Entonces, ¿la solución es obtener los scripts por ID y cambiar el tipo de script2.js de text/javascript a module?

¿Hay alguna otra forma de cambiar el script2.js al módulo?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede agregar un archivo .mjs .

Ejemplo

 // index.js import otherFile from './otherFile.js';
 // otherFile.js import otherOtherFile from './otherOtherFile.mjs'; export default './otherFile.js';
 // otherOtherFile.mjs export default 'otherOtherFile.mjs';
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!