etienne-martin / svg-to-img

A node.js library to convert SVGs to images built with Puppeteer.
MIT License
56 stars 22 forks source link

UnhandledPromiseRejectionWarning: Error: Evaluation failed #10

Closed torrfura closed 5 years ago

torrfura commented 5 years ago

Running a clean install, using your logo.svg and your code:

const svgToImg = require("svg-to-img");
(async () => {
  const image = await svgToImg.from("logo.svg").toPng();
  console.log(image);
})();

Result in:

(node:2990) UnhandledPromiseRejectionWarning: Error: Evaluation failed: Error: Malformed SVG
    at Image.onError (__puppeteer_evaluation_script__:57:20)
    at ExecutionContext.evaluateHandle (/Users/xxx/test/node_modules/puppeteer/lib/ExecutionContext.js:90:15)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
  -- ASYNC --
    at ExecutionContext.<anonymous> (/Users/xxx/test/node_modules/puppeteer/lib/helper.js:144:27)
    at ExecutionContext.evaluate (/Users/xxx/test/node_modules/puppeteer/lib/ExecutionContext.js:58:31)
    at ExecutionContext.<anonymous> (/Users/xxx/test/node_modules/puppeteer/lib/helper.js:145:23)
    at Frame.evaluate (/Users/xxx/test/node_modules/puppeteer/lib/FrameManager.js:447:20)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
  -- ASYNC --
    at Frame.<anonymous> (/Users/xxx/test/node_modules/puppeteer/lib/helper.js:144:27)
    at Page.evaluate (/Users/xxx/test/node_modules/puppeteer/lib/Page.js:777:43)
    at Page.<anonymous> (/Users/xxx/test/node_modules/puppeteer/lib/helper.js:145:23)
    at convertSvg (/Users/xxx/test/node_modules/svg-to-img/dist/index.js:66:31)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
torrfura commented 5 years ago

Obviously seems like something is broken in later versions of puppeteer, might be a good call to lock down versions in package.json to prevent future issues like these.

vaxerski commented 5 years ago

npm uninstall puppeteer --save

npm install puppeteer@1.6.1 --save

hope this helps

etienne-martin commented 5 years ago

Thanks for reporting the issue. The solution was to lock the dependencies.

etienne-martin commented 5 years ago

https://github.com/etienne-martin/svg-to-img/commit/4d872d87c908e2bd2ac975fe31a38c3cbb95cbee

ibrazug commented 2 years ago

I still have the same problem.

MariaIsabel68 commented 1 year ago

any solution?

ibrazug commented 1 year ago

any solution?

Just use sharp JS const svgBuffer = Buffer.from(mySVG); const image = await sharp(svgBuffer).toFormat("png").toBuffer(); const imageSource = data:image/png;base64,${image.toString("base64")};