Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import matter-js in typescript project

I found this file :

https://www.npmjs.com/package/@types/matter-js

i execute this line :

npm install --save @types/matter-js

In root ts file i got error message :

'Matter' refers to a UMD global, but the current file is a module. Consider adding an import instead.

Code looks like :

///<reference path="matter-js.d.ts"/>

import Ioc from "./libs/ioc";
let master = new Ioc();
console.log(master);
console.log(Matter);

Error in browser:

app.ts:11 Uncaught ReferenceError: Matter is not defined

Did i need to load matter-js.js lib ?

If i put :

import matter from 'matter-js'

i get :

Module ''matter-js'' has no default export.

like image 499
Nikola Lukic Avatar asked Apr 09 '18 13:04

Nikola Lukic


3 Answers

You can try to load it using import * as matter from 'matter-js', that should work.

like image 86
felixmosh Avatar answered Nov 10 '22 13:11

felixmosh


I load the matter.js library with a script tag. Did you forget that?

<script src="js/matter.min.js"></script>

And I installed the typings with

npm install @types/matter-js
like image 35
Kokodoko Avatar answered Nov 10 '22 13:11

Kokodoko


Unfortunately, the typescript lib seems outdated. Last commit 2 years ago. Parameters that should be optional are instead required in the typescript definitions...

like image 2
user3547989 Avatar answered Nov 10 '22 13:11

user3547989