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

430
Views
Javascript: Uncaught SyntaxError: export declarations may only appear at top level of a module

I'm writing a vanilla JS project and I'm encountering an issue.

test1.js:

export default foo;

function foo() {
    const something = "a";
}

test2.js:

import foo from test1.js;

foo();

console.log(something);

But when I try to run it in my browser (Firefox), I get Uncaught SyntaxError: export declarations may only appear at top level of a module.

Can anyone help? Thanks a lot!

Edit: Thanks a lot!

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

0

you can't call a variable which is inside function. Instead of that you can write :

export default foo;

function foo() {
    const something = "a";
    console.log(something)
}

then :

import foo from 'test1.js';

foo();

and in your HTML template : <script src="test2.js" type="module"></script>

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!