Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
irv-armenta-g opened this issue Sep 18, 2024 · 1 comment

Comments

@irv-armenta-g
Copy link

irv-armenta-g commented Sep 18, 2024

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 ./

@scriptex
Copy link
Owner

scriptex commented Sep 18, 2024

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 scriptex changed the title svg-symbol-sprite not getting/finding the config file svg-symbol-sprite not getting/finding the config file when using pnpm Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants