svg.draggable.js icon indicating copy to clipboard operation
svg.draggable.js copied to clipboard

This plugin is incompatible with the latest version svg.js

Open suasti opened this issue 3 years ago • 7 comments

I got ReferenceError: SVG is not defined node_modules/@svgdotjs/svg.draggable.js/dist/svg.draggable.js

suasti avatar Jul 08 '21 15:07 suasti

more context please. Did you include the files in teh correct order? Whee do you got your svg.js from?

Fuzzyma avatar Jul 08 '21 16:07 Fuzzyma

I'm also running into this same error trying to use this plugin against @svgdotjs/svg.js version 3.1.1 installed through npm. I'm following the ES import instructions from the readme,

import { SVG } from '@svgdotjs/svg.js'
import '@svgdotjs/svg.draggable.js'

cornwe19 avatar Aug 12 '21 04:08 cornwe19

Are you using native esm support or some kind of bundler? What's your ecosystem?

Fuzzyma avatar Aug 12 '21 05:08 Fuzzyma

This is a NextJS React app using webpack 5.

For what it's worth, I did find a workaround. Looks like if I require the plugin inside a useEffect during the first render instead of importing it everything works as expected.

import {SVG, Element, Container} from "@svgdotjs/svg.js"

const MyComponent = () => {
  useEffect(() => require('@svgdotjs/svg.draggable.js'), [SVG])
  ...
}

cornwe19 avatar Aug 12 '21 12:08 cornwe19

Putting it in useEffect doesn't seem efficient. Any solution for this one ?

anup-a avatar Oct 01 '22 11:10 anup-a

@anup-a FWIW the workaround I suggested would effectively only render once when the component is mounted. Are you concerned about rerenders?

cornwe19 avatar Oct 02 '22 21:10 cornwe19

@anup-a FWIW the workaround I suggested would effectively only render once when the component is mounted. Are you concerned about rerenders?

Yes. also a little bit worried about the bundling and minification. I don't know how webpack/swc handles such imports.

Although the setup looks correct, with the externals and IIFE pattern, don't know what is causing the issue.

anup-a avatar Oct 04 '22 16:10 anup-a