2

I'm trying to import a Class from and external document into my web with the following code.

``` 
[File : root/js/circle.js]
// Circle object
export class Circle{
  constructor(position,size){
    this.position = position;
    this.size = size;
  }

  checkCollision(circle){
    return  this.position.distance2D(circle.position) <= (circle.size + this.size);
  }

  show(){
    ellipse(this.position.x, this.position.z);
    return;
  }

  lineTo(circle){
    line(this.position.x, this.position.z, circle.x, circle.z);
    return;
  }
}
console.log(Circle);
```
```
[File : root/js/main.js]
import {Circle} from './circle.js';
```
```
[File : root/index.html] 
<script type="module" src="js/main.js"></script>
``` 

My problem is that i can't access the "Circle" class from main.js, if i try to use "Circle" it returns "undefined", but i can see the "console.log" from circle.js.

5
  • Which build tools are you using? This looks like a circular dependency issue at first sight. Commented Jan 10, 2019 at 11:21
  • I don't have any dependency yet, i used my own set of functions for this, and there is none called "Circle" : i.gyazo.com/a36b6a488b2d2f07ab8d2273398f9f74.png Also, im using XAMP for the server and the browser its Google Chrome. Commented Jan 10, 2019 at 11:25
  • when i run your code in main.js i can do new Circle(0, 0) and get a new instace of the Circle class. what is your exact code that prints undefined? Commented Jan 10, 2019 at 11:38
  • " console.log(new Circle(0,0)) " i.gyazo.com/054fe508666aa91b61b53bd8e53997d9.png I'm really confused now, i tried to coment everything else, and it still give me the same error Commented Jan 10, 2019 at 11:44
  • Does this answer your question? import returns undefined instead of react component while testing Commented Dec 17, 2021 at 17:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.