svg-sprite / svg-sprite

SVG sprites & stacks galore — A low-level Node.js module that takes a bunch of SVG files, optimizes them and bakes them into SVG sprites of several types along with suitable stylesheet resources (e.g. CSS, Sass, LESS, Stylus, etc.)

Home Page:https://github.com/svg-sprite/svg-sprite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Output sprite empty after migrating to v3

fallemand opened this issue · comments

It seems that if the svg contains any child, the output of the sprite is empty.

The error is the following:

2023-10-16 16:10:24.124 - info: Created spriter instance
2023-10-16 16:10:24.129 - error: Skipping "icon-test.svg" (Cannot read properties of null (reading 'localName'))

Here is a minimal reproduction.

const spriter = new Spriter({
   log: "verbose",
    mode: {
      symbol: true,
    },
  });

  spriter.add(
    "./icon-test.svg",
    "icon-test.svg",
    // Does not work
    '<svg><circle cx="50" /></svg>',
    // Does work
    // "<svg></svg>",
  );

  // Generate sprite
  spriter.compile((error, result) => {
    if (error) {
      console.error("Could not complile SVG sprite", error);
      process.exit(1);
    }

    Object.values(result).forEach((mode) => {
      Object.values(mode).forEach((resource) => {
        fs.writeFileSync(resource.path, resource.contents);
        console.info(`\nSprite generated: ${resource.path}`);
      });
    });
  });

Tried with all versions and the issue is the same:
3.0.0-alpha1
3.0.0-alpha2
3.0.0-beta1
3.0.0-beta2

Works well with: 2.0.2

Same issue here, I get empty svg with v3 but works with v2.

This is a regression due to xmldom >=0.8.8. I'll push later/tomorrow a new beta with xmldom pinned to 0.8.8.

I don't have the time to debug this further or report the issue upstream, so if someone can do either of these 2 that would help more people.

@XhmikosR I tested 3.0.0-beta3 today and was able to successfully generate sprites that contained <circle.... Thank you!