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

135
Views
Javascript imports and classes

I've been looking for an answer for days and can't find one. So here it is. I have 3 files. We'll call them main.js, classA.js and classB.js. In the HTML I set the script to module with the arc of main.js.

Now, I import classA and classB in to main without issue. The problem I'm having is classA isn't seeing classB Even though I'm using the same import line for classB in classA.

The console says the classB is undefined. Am I missing something or do I have to put all my classes in one file?

// index.js
import ClassB from ".\ClassB.js"
import ClassA from ".\ClassA.js"

let classA = new ClassA();

// ClassA.js
import ClassB from ".\ClassB.js"

export default class ClassA(){
  let classB = new ClassB();
  constructor(){}
}

// ClassB
export default class ClassB(){
  constructor(){}
}
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!