Class from NPM package not recognized

I have this code in the beginning of my javascript:

alert(“Page is loaded”);
var Engine = Matter.Engine,

and I verified that the alert popped up, therefore the script being executed. But the browser page shows this error:
script.js:3 Uncaught ReferenceError: Matter is not defined at script.js:3

However, “Matter” is a class from a package called matter-js which I already included in my package.json:

“dependencies”: {
“express”: “^4.17.1”,
“matter-js”: “^0.14.2”

(which I added using Add Package button so glitch knows about that package). I also remixed the project after adding the package. So I wonder what I’m missing.

thank you!

You can’t use packages from package.json in client side code unless you use webpack. I’d recommend adding this to your html file:

<script src="//"></script>

Please let me know if that works or not.


Hello, this works perfectly. Thank you!

1 Like