funbox / optimizt

CLI image optimization tool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CLI breaks when hitting SVGs

edzis opened this issue Β· comments

When the directory contains an svg file the CLI stops with the following error.

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined
    at Object.statSync (node:fs:1529:10)
    at /Users/###/node_modules/@funboxteam/optimizt/lib/optimize.js:76:18
    at Array.forEach (<anonymous>)
    at optimize (/Users/###/node_modules/@funboxteam/optimizt/lib/optimize.js:74:15)
    at async optimizt (/Users/###/node_modules/@funboxteam/optimizt/index.js:18:5) {
  code: 'ERR_INVALID_ARG_TYPE'
}

When I add filtering for errors via const tasksResult = (await Promise.all(tasks)).filter(res => !!res); in optimize.js I see the following output for those svg files:

βœ– /Users/###/src/images/###.svg
   parseName is not a function

The SVG issue might be introduced in f4510cb.

But error filtering should be applied in any case.

@edzis, hey there!

@343dev has fixed this behavior in #35. Would you mind to try again? 🐨

@igoradamenko @343dev There seems to be another issue:

➜  my-project git:(develop) optimizt ./src
node:internal/modules/cjs/loader:928
  throw err;
  ^

Error: Cannot find module '../node_modules/svgo/lib/xast.js'
Require stack:
- /Users/X/.config/yarn/global/node_modules/@funboxteam/optimizt/svgo/removeUnknownsAndDefaults.js
- /Users/X/.config/yarn/global/node_modules/@funboxteam/optimizt/svgo/config.js
- /Users/X/.config/yarn/global/node_modules/@funboxteam/optimizt/lib/optimize.js
- /Users/X/.config/yarn/global/node_modules/@funboxteam/optimizt/index.js
- /Users/X/.config/yarn/global/node_modules/@funboxteam/optimizt/cli.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Module.require (node:internal/modules/cjs/loader:997:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (/Users/X/.config/yarn/global/node_modules/@funboxteam/optimizt/svgo/removeUnknownsAndDefaults.js:4:45)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:973:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:997:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/X/.config/yarn/global/node_modules/@funboxteam/optimizt/svgo/removeUnknownsAndDefaults.js',
    '/Users/X/.config/yarn/global/node_modules/@funboxteam/optimizt/svgo/config.js',
    '/Users/X/.config/yarn/global/node_modules/@funboxteam/optimizt/lib/optimize.js',
    '/Users/X/.config/yarn/global/node_modules/@funboxteam/optimizt/index.js',
    '/Users/X/.config/yarn/global/node_modules/@funboxteam/optimizt/cli.js'
  ]
}

@edzis, it looks like the current behavior is somehow related to the difference between npm and yarn.

@343dev has probably fixed the error in #37. We've published the fix as @funboxteam/optimizt@2.7.5-rc. Would you mind to check it?

@edzis, woooosh! We've published one more RC version. Please, use this for the check: @funboxteam/optimizt@2.7.5-rc.2.

πŸ˜…

πŸ‘Œ this works now and processes also the svg files! Thanks for your care!
I wish I had raised my concerns about require('../node_modules/svgo/... earlier.

No problem. Thank you for the report!

We've finally published @funboxteam/optimizt@2.7.5 πŸŽ‰