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

convert-svg-to-webp: Cannot read properties of undefined (reading 'html') #111

Open
it1shka opened this issue Nov 20, 2024 · 2 comments
Open

Comments

@it1shka
Copy link

it1shka commented Nov 20, 2024

I have a simple script for converting svg to webp:

#!/opt/homebrew/bin/node

const fs = require('fs')
const path = require('path')
const util = require('util')
const svgToWebp = require('convert-svg-to-webp')

const svgFolder = path.join(process.cwd(), 'assets')
const webpFolder = path.join(process.cwd(), 'assets-webp')

const main = async () => {
  if (!fs.existsSync(webpFolder)) {
    await util.promisify(fs.mkdir)(webpFolder)
  }

  const filenames = await util.promisify(fs.readdir)(svgFolder)
  for (const filename of filenames) {
    const filepath = path.join(svgFolder, filename)
    util.promisify(fs.lstat)(filepath).then(async stats => {
      if (stats.isDirectory()) return
      console.log(`Converting: ${filepath}`)
      const webpFilename = filename.replace('.svg', '.webp')
      const webpFilepath = path.join(webpFolder, webpFilename)
      await svgToWebp.convertFile(filepath, {
        outputFilePath: webpFilepath ,
      })
      console.log(`Created: ${webpFilepath}`)
    })
  }
}

main()

I get the following error:

/opt/homebrew/bin/lib/node_modules/convert-svg-to-webp/node_modules/convert-svg-core/src/Converter.js:264
    const svg = cheerio.default.html(this[_sanitize](cheerio.load(input, null, false)('svg:first'), options));
                                ^

TypeError: Cannot read properties of undefined (reading 'html')
    at [convert] (/opt/homebrew/bin/lib/node_modules/convert-svg-to-webp/node_modules/convert-svg-core/src/Converter.js:264:33)
    at Converter.convertFile (/opt/homebrew/bin/lib/node_modules/convert-svg-to-webp/node_modules/convert-svg-core/src/Converter.js:221:40)
    at async API.convertFile (/opt/homebrew/bin/lib/node_modules/convert-svg-to-webp/node_modules/convert-svg-core/src/API.js:116:24)
    at async /Users/tikhon/Documents/scripts/imgconv2.js:24:7

Node.js v23.2.0
@shivaRamdeen
Copy link

shivaRamdeen commented Dec 10, 2024

This PR seems to fix it:
https://github.com/neocotic/convert-svg/pull/110/files#diff-8439b5501fb8f6b2dc296e5b48fc53c284d02b9847f88454687f20e3b069c619

@rkanumola
Copy link

Hi Team / @shivaRamdeen ,

Can you please prioritize the fix to go live as we are seeing a quite a few of these entries in our log and we have limiations to our logging app which is being impacted with these unwanted log entries, Hope you understand our problem and will look into this at the earliest as possible.

Thanks
RK

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

3 participants