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

357
Views
Uncaught ReferenceError: Function not found in module

I have my file structure like this:

classfile.js

class Car {
    constructor(name, year) {
      this.name = name;
      this.year = year;
    }
  }

mainfile.js

import {Car} from './classfile.js';  // Added this
const myCar = new Car("Ford", 2014);

function myFunction() {
    document.getElementById('demo').innerHTML = myCar.name + " " + myCar.year;   
}

main.html

<!DOCTYPE html>
<html>
    <head>
        <script src="classfile.js"></script>
        <script type="module" src="mainfile.js"></script>
    </head>
<body>
<h2>JavaScript Class</h2>
<p>How to use a JavaScript Class.</p>
<p id="demo" onclick="myFunction()">Click Me</p>
</body>
</html>

I keep getting errors myFunction() is not defined.

How do I make functions in module type to execute?

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!