Snap SVG with Typescript and Webpack error “Cannot read property 'on' of undefined”

后端 未结 2 1821
死守一世寂寞
死守一世寂寞 2021-01-28 08:48

I have an Angular 4 app using Snap SVG and I get the dredded webpack problem \"Cannot read property \'on\' of undefined\".

Using snapsvg-cjs seems to be the simplest w

相关标签:
2条回答
  • 2021-01-28 09:08

    Ok, I see what I did now. Using snapsvg-cjs just works. I get typescript support.

    0 讨论(0)
  • 2021-01-28 09:09

    I had this same issue. For me, I installed snapsvg-cjs and @types/snapsvg, then imported the library as so:

    import "snapsvg-cjs"
    

    You only need to import it this way once (maybe in a main.ts file or something)

    Then in the file where you want to use the library, import the types as so:

    import * as SNAPSVG_TYPE from "snapsvg"
    declare var Snap: typeof SNAPSVG_TYPE
    

    This allowed me to use the typescript types like normal while still employing the webpack compatible version.

    0 讨论(0)
提交回复
热议问题