I am making a project using MatterJS. However, I am having some difficulties. Whenever I run my code it throws the error TypeError: Composite.add(...) is not a function. I checked to make sure that MatterJS was added correctly by adding the following snippet to my code:
if(Composite.add){
console.log(Composite.add)
}
Upon running, the code put in the console the contents of Composite.add, and it is definitely defined as a function. Yet it still says that Composite.add is not a function. What can I do to fix this?
Here is the relevant portion of my code:
// module aliases
var Engine = Matter.Engine,
Render = Matter.Render,
Runner = Matter.Runner,
Bodies = Matter.Bodies,
Composite = Matter.Composite,
Body = Matter.Body,
Events = Matter.Events;
World = Matter.World;
// const G = 1;
// var mouse;
// let path = [];
if (Composite.add) {
console.log('Composite.add found')
}
// create an engine
var engine = Engine.create({
gravity: {
x: 0,
y: 1,
scale: 0
}
});
world = engine.world;
var w = window.innerWidth;
var h = window.innerHeight;
var canvas = document.getElementById('canvasM');
let ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
let circleA = Bodies.circle(100, 100, 10);
console.log(circleA.area)
//the error is thrown here ↓
Composite.add(world, [circleA])
<script src='https://cdn.jsdelivr.net/gh/liabru/[email protected]/build/matter.js'></script>
<canvas id="canvasM" data-pixel-ratio="2" style="position:relative; z-index:0;"></canvas>


