svgdotjs / svg.js

The lightweight library for manipulating and animating SVG
https://svgjs.dev
Other
10.95k stars 1.07k forks source link

3.0.0 import not working #1272

Closed noah-seltzer closed 1 year ago

noah-seltzer commented 2 years ago

I've been happily using SVGJS 3.0.0 with svgdom in nodejs with no issues for years. Today I tried to move some of my SVGJS code into the browser, but I can't seem to import it with the standard import { SVG } from '@svgdotjs/svg.js'

Is there anything I'm doing wrong here?

My front end stack is nuxt 3 + vue 2

Fuzzyma commented 2 years ago

Please look into how esm modules are loaded in the browser. node knows what npm is and that it can find its modules on node_modules. The browser doesn't. You have to give it the correct path to the javascript files

In case you know that and you use a bundler already, I don't really have an idea why it is not working. Can you share a reproduction in this case?

MeesMaas commented 1 year ago

You should try the following in your Vue component:

const SVG = require('@svgdotjs/svg.js');

Worked for me

noah-seltzer commented 1 year ago

its been too long since the original comment for me to remember what I did, but I just checked my repo and import { SVG } from '@svgdotjs/svg.js' is working just fine. Must have been a webpack issue

noah-seltzer commented 1 year ago

thanks everyone who commented :)