adobe-webplatform / Snap.svg

The JavaScript library for modern SVG graphics.
http://snapsvg.io
Apache License 2.0
13.91k stars 1.15k forks source link

imports-loader rule is not compatible with imports-loader@3.0.0 #653

Open tensory opened 2 years ago

tensory commented 2 years ago

I'm using Webpack 5.45.1 and imports-loader 3.0.0.

The suggestion in the Readme to use imports-loader with an argument use: "imports-loader?this=>window,fix=>module.exports=0" is not compatible with latest imports-loader.

I was able to get the bundle file to build using this rule, updated using imports-loader 3.0.0 docs:

module: {
    rules: [
      // snapsvg depends on imports-loader
      {
        test: require.resolve('snapsvg/dist/snap.svg.js'),
        // not working!
        // use: 'imports-loader?this=>window,fix=>module.exports=0',
        use: [
          {
            loader: "imports-loader",
            options: {
              wrapper: "window",
              additionalCode: "module.exports=0"
            }
          }
        ],
      },
    ],
    ...

I would love to contribute this update as a pull request to the Readme. Unfortunately I'm still getting an error at runtime about Uncaught ReferenceError: eve is not defined, so it didn't solve the underlying problem that I thought the rule might address.

hailie-rei commented 2 years ago

@tensory Hi, I faced the same issue for Webpack 5, and I solved it by using https://github.com/ThomasOrlita/Snap.svg-cjs. No need to use imports-loader.

Just import Snap from "snapsvg-cjs";

abid-mujtaba commented 1 year ago

This can be solved without having to switch to a different project using the solution in https://github.com/adobe-webplatform/Snap.svg/issues/639