I am trying to import the class Paddle from the paddle.js file but it keeps getting an error of "Error: SyntaxError: Cannot use import statement outside a module". The files are in the same folder.
Here's my import code (from game.js file):
import Paddle from "/paddle.js";
let canvas = document.getElementById("screen");
let ctx = canvas.getContext("2d");
const game_width = 800;
const game_height = 600;
ctx.clearRect(0, 0, 800, 600);
and here's my code from paddle.js:
export default class Paddle {
constructor(gameWidth, gameHeight){
this.width = 150;
this.height = 30;
this.position = {
x: gameWidth / 2 - this.width / 2,
y: gameHeight - this.height - 10,
}
}
draw(ctx){
ctx.fillRect(this.position.x, this.position.y, this.width, this.height);
}
update(deltaTime){
if(!deltaTime) return;
this.position.x += 5 / deltaTime;
}
}