piqnt / svgexport

SVG to PNG/JPEG command-line tool and Node.js module
927 stars 85 forks source link

Unable to load file on Windows #72

Closed jindrazak closed 4 years ago

jindrazak commented 4 years ago

I am facing trouble exporting svg to png on Windows.

Way to reproduce:

Powershell:

> npm i svgexport -g
... OK
> svgexport.cmd .\inputimage.svg outputimage.png
Error: Unable to load file (Error: net::ERR_INVALID_URL at file://C:%5CUsers%5Cjindr%5Cinputimage.svg): C:\Users\jindr\inputimage.svg
jefago commented 4 years ago

I have the same issue. Works with 0.3.2, stopped working with 0.4.0.

jefago commented 4 years ago

The problem is here: https://github.com/shakiba/svgexport/blob/master/render.js#L30

On Windows, svgfile will be something like C:\users\...., so the URL that gets created is file://C:\users\..., but it should be file:///C:/users/ (three forward slashes, backslashes replaced by forward slashes although I'm not certain the latter is needed).

MichaelRoosz commented 4 years ago

Yes, I have already prepared a fix for Windows. There is still another Windows bug to be fixed, once this is done we can release a new version.

roman-petrov commented 4 years ago

@MichaelHeerklotz , any chance to make the latest version work on Windows soon? :)

MichaelRoosz commented 4 years ago

@roman-petrov I am aiming for a release this week. Sorry for taking so long.

roman-petrov commented 4 years ago

@MichaelHeerklotz , sounds great! Thank you!

liuchaobit commented 4 years ago

I have the same problem where can I find the latest version

ctch3ng commented 4 years ago

For Windows users, in %AppData%\npm\node_modules\svgexport\render.js

Change the line

await page.goto('file://' + encodeURI(svgfile))

into

await page.goto('file:///' + encodeURI(svgfile).replace(new RegExp(/%5C/g),"/"))

jindrazak commented 4 years ago

@ctch3ng Wouldn't it be better to apply a pull request?

jamesmontalvo3 commented 4 years ago

Submitted #83. Resolved issues on Windows for me. Haven't tested on other systems.

silverwind commented 4 years ago

Alternative PR: https://github.com/shakiba/svgexport/pull/86