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

239
Views
Cannot use import statement outside a module when trying to import from other js file

Hi so i'm relatively new to programming and still learning. so the problem is i have 4 files index.html, index.js, teacher.js, person.js. the teacher module contain class Teacher and the person module contain class Person. when i try to import it to index.js it shows Cannot use import statement outside a module in the browser. can someone help? thanks.

index.js file

import {Teacher} from "./teacher";
const teacher = new Teacher("Mosh", "MSc");
teacher.teach();

person.js file

export class Person {
  constructor(name) {
    this.name = name;
  }

  walk() {
    console.log("walk");
  }
}

teacher.js file

import {Person} from "./person";

export class Teacher extends Person {
  constructor(name, degree) {
    super(name);
    this.degree = degree;
  }
  teach() {
    console.log("teach");
  }
}
about 4 years ago · Juan Pablo Isaza
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!