import * as snapsvg from 'snapsvg';
var s = snapsvg.Snap(800,600);
Error:
Uncaught TypeError: Cannot read property 'on' of undefined
I saw, that more people have problem with importing third party libraries. Am I doing something wrong or it’s common problem with Ionic2 beta version? Any advices?
Daniel Rosenwasser, one of the author of Typescript, explained to me that I had to add those 3 lines at the end of the snap svg d.ts file, as it is not declared as a module:
declare module “snapsvg” {
export = Snap;
}
I contributed those lines to github but it looks like it’s not been released.
So:
Add those 3 lines as described
to use:
import snap = require(“snapsvg”)
I asked him the difference between import snap = require(“snapsvg”) and import * as snap from “snapsvg”;
His answer:
There is no difference for the emit. Unfortunately, Node didn’t give a very good interop story at all for ES modules. Technically, import * as snap from “snapsvg” means that ‘snap’ is not callable, because the ES6 spec says that namespace imports (the ones that are written ‘* as foo’) aren’t callable, so I’d stick with import = require.
Finally, if you use webpack, here’s how to make sure it works:
@gregoryforel, I tried this and still get the error. Windows 10. VS Code. Ionic 2.0.1. snapsvg 0.5.1
Could you show the min TS and HTML and exactly where to put these lines in the typings file? Thanks