svg-symbol-sprite icon indicating copy to clipboard operation
svg-symbol-sprite copied to clipboard

svg-symbol-sprite not getting/finding the config file when using pnpm

Open irv-armenta-g opened this issue 1 year ago • 3 comments

I am trying to use a custom config file (svgo.config.js) but it seems svg-symbol-sprite is unable to find it's location, even though it is in the same level as the script.

I have another project where I am using yarn and in that project it does seem to be working correctly.

In this current project I am using pnpm as the package manager and script runner, I am using tsx to run a specific file in root called generate-svg-icons.ts

 "scripts": {
    "generate:icons": "tsx generate-svg-icons.ts",
  },

This file uses execSync to call the inline CLI script, it's inside a fs.readDir call with other async functions in order to follow an order in execution.

fs.readdir(iconsDirectory, (error, files) => {
    fs.writeFile(distributionFilePath, tsFileContents, async (error) => {
     
     // async logic....
     
     execSync(
      `pnpm svg-symbol-sprite -i public/icons -o public/${svgSymbolsFileName} -c ./svgo.config.js`,
      { stdio: 'inherit' }
    );
  });
});

edit: I also have tried withouth ./ as it is stated should be "absolute" but I get the same result"

I have tried so many ways, even using path.resolve() also tried adding the inline script in a separate script key and still I keep getting the same message:

SVG Symbol Sprite: SVGO configuration file not found. Using default SVGO configuration.

is this related to pnpm being the package manager? Information about my environment:

OS: windows 
NODE: v20.17.0
package manager: pnpm
script runner: tsx 

generate-svg-icons.ts and svgo.config.js both are in the same level at root ./

irv-armenta-g avatar Sep 18 '24 06:09 irv-armenta-g

Thanks for opening this and sorry for the troubles which you have. I haven't tried this with pnpm but it looks like this might be the issue here as it works correctly with yarn or npm. I also haven't used the module programatically as you do.

One thing which comes into my mind is adding a new script under scripts of your package.json like this:

{
  "scripts": {
    "svg-sprite": "svg-symbol-sprite -i public/icons -c ./svgo.config.js"
  }
}

and then execute it inside your script file like this

execSync(`pnpm run svg-sprite -o public/${svgSymbolsFileName}`, { stdio: 'inherit' });

Disclaimer: I haven't used pnpm and have no idea how it plays with stdio: 'inherit'.

If this doesn't work maybe you can verify that actually pnpm is causing the issues by temporarily switching to npm or yarn?

Let me know how this goes.

scriptex avatar Sep 18 '24 10:09 scriptex

I have just upgraded to node 22 ... and now I am running into this issue as well. For a while "svg": "pnpm dlx svg-symbol-sprite -i ./icons -o ./static/sprites.svg" has been working well for me and now not anymore. I have tried reverting back and setting node engines in the package json. alas something weird is going on.

vonKristoff avatar Jul 15 '25 11:07 vonKristoff

Using npx over pnpm does allow the lib to work as expected.

vonKristoff avatar Jul 15 '25 11:07 vonKristoff