svg / svgo

⚙️ Node.js tool for optimizing SVG files
https://svgo.dev/
MIT License
21.04k stars 1.39k forks source link

`nxp svgo@latest a.svg -o b.svg` doesn't work #1970

Closed retyui closed 8 months ago

retyui commented 8 months ago

Describe the bug

can'r use svgo with npx it complaint "no such file"

To Reproduce

ls  # info.svg

npx svgo@latest info.svg -o info.min.svg   
# Error: no such file or directory 'info.svg'.

#    at checkOptimizeFileError (/Users/i/.npm/_npx/2be8efd978f68697/node_modules/svgo/lib/svgo/coa.js:492:7)
#    at /Users/i/.npm/_npx/2be8efd978f68697/node_modules/svgo/lib/svgo/coa.js:373:16
#    at async Promise.all (index 0)
#    at async Command.action (/Users/i/.npm/_npx/2be8efd978f68697/node_modules/svgo/lib/svgo/coa.js:262:7)
#    at async Promise.all (index 0)

Expected behavior

work properly

Screenshots

...

Desktop (please complete the following information):

Additional context

...

SethFalco commented 8 months ago

I've been unable to reproduce this on Debian (Linux). I get the same error as you if the file indeed does not exist, but if I create the file, everything works as intended.

Can you please try the following and share the result, just to confirm 100% that this is indeed the scenario you've encountered:

(
  # create a temp directory and cd to it (usually /tmp)
  cd $(mktemp -d)
  # create a mock svg
  echo '<svg></svg>' > original.svg
  # optimize the svg with svgo
  npx svgo@latest original.svg
)
retyui commented 8 months ago

you right from tmp folder it works,

 npx svgo@latest original.svg                                                    
 --- xdebug {
  cwd: '/private/var/folders/_z/vx08z2b93ylfqdxv3n2hp7qm0000gp/T/tmp.ALluj36Grh',
  file: 'original.svg',
  __dirname: '/Users/i/.npm/_npx/2be8efd978f68697/node_modules/svgo/lib/svgo'
}

original.svg:
Done in 3 ms!
0.006 KiB - 0% = 0.006 KiB

but if I run it from my yarn monorepo project

cd /Users/i/all_work/ck/dtv/app/libs/shared-icons/SVGs
npx svgo@latest search.svg          

 --- xdebug {
  cwd: '/Users/i/all_work/ck/dtv/app/libs/shared-icons',
  file: 'search.svg',
  __dirname: '/Users/i/.npm/_npx/2be8efd978f68697/node_modules/svgo/lib/svgo'
}
Error: Error: no such file or directory 'search.svg'.
    at checkOptimizeFileError (/Users/i/.npm/_npx/2be8efd978f68697/node_modules/svgo/lib/svgo/coa.js:497:7)
    at /Users/i/.npm/_npx/2be8efd978f68697/node_modules/svgo/lib/svgo/coa.js:378:16
    at async Promise.all (index 0)
    at async Command.action (/Users/i/.npm/_npx/2be8efd978f68697/node_modules/svgo/lib/svgo/coa.js:262:7)
    at async Promise.all (index 0)
retyui commented 8 months ago

so the problem in case of monorepo process.cwd() is /Users/i/all_work/ck/dtv/app/libs/shared-icons/