konsumer / inkscape-svgo

Plugin to optimize SVGs in inkscape
73 stars 7 forks source link

"File yadda/yadda can not be saved" #1

Closed brennanyoung closed 5 years ago

brennanyoung commented 5 years ago

I'm trying out inkscape-svgo on Windows 8.1. I believe it's installed in the correct place. I put inkscape-svgo.inx in C:\Program Files\Inkscape\share\extensions

Then I make a simple barebones inkscape document, or open an existing svg, and choose "SVGO optimized SVG file" from Save As... popup. The UI opens.

But when I finish clicking boxes and click "OK", I see the command window open briefly, with some kind of error trace, and then get an error alert saying "File D:\yadda\yadda\whatever.svg" can not be saved"

I have no trouble saving to that location if I just use Save As Inkscape SVG.

For good measure, I installed command line svgo as well. This seems to work fine.

What am I missing? Any way to keep command window open so I can read the error trace?

brennanyoung commented 5 years ago

OK, I managed to find the .cmd file where I could add a pause, and got this:

events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: spawn C:\Users\foobar\AppData\Roaming\npm\node_modules\inkscape-svgo/node_modules/.bin/svgo ENOENT
    at exports._errnoException (util.js:1022:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
    at onErrorNT (internal/child_process.js:359:16)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)
    at Module.runMain (module.js:606:11)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3
konsumer commented 5 years ago

Sorry, I have been busy and didn't have time to look into this until now.

Hopefully it will be helpful to explain what I did.

I tested on a windows 10 virtual-machine. It should be similar to windows 8, and if you can't get it working let me know, and I will try to rustle up a win8 vmachine.

When I tested, I got an error about ssh when I ran npm i -g konsumer/inkscape-svgo so I published this package on npm to make it easier for non-*nix people (no ssh needed in path.)

Here was my whole process, after that:

After this, I got another path error, that I'm not really sure about the cause of, but I think it might be how inkscape handles extensions on windows (my username has a space in it, which seems to be freaking something out, ugh.)

Screenshot_2019-04-23_16-24-59

If you can get passed this point, you should be all set.

I may need to rewrite this extension in python or something, to make it work on windows, I'm really not sure. The path thing is super-annoying.

konsumer commented 5 years ago

So, basically, the short of the long is that inkscape-svgo needs to be in your path, as well as svgo and since it's currently published on npm, as long as you don't have the issue I had, npm i -g inkscape-svgo should do that for you (as it installs both packages in 0.0.4.)

konsumer commented 5 years ago

It seems like most inkscape plugins are distributed as a python + inx file, even though their docs say "use any script language" so I wouldn't mind rewriting it as a python script (the actual plugin code is a pretty simple wrapper around svgo) if I have to. It might also be possible to directly use the svgo API in code, instead of building CLI params. I will look into the second option, as it seems like the nicest way so we all get what we need from this module, and I can keep it in nodejs.

konsumer commented 5 years ago

Give the new version (0.0.7) a go, and let me know if it has issues. I am building options for svgo lib instead of CLI params, which seems to resolve path problems for me.

brennanyoung commented 5 years ago

Just tried npm i -g inkscape-svgo which gave me 0.0.7 but it still failed with the same error. FWIW I also tried saving on different drives.

konsumer commented 5 years ago

Hmm. Very strange. Maybe we are both getting a path error from how it is worked out in the inx file. At this point, the script itself calls the API directly, so I can only assume it's in the way inkscape calls the script. I will need to look at it some more.

brennanyoung commented 5 years ago

FWIW I did not move any files after running npm i -g inkscape-svgo. Maybe that's why?

Also I get a syntax(!) error when I run inkscape-svgo

C:\Users\foo\AppData\Roaming\npm\node_modules\inkscape-svgo\inkscape-svgo.js:7
const main = async () => {
                   ^
SyntaxError: Unexpected token (
    at Object.exports.runInThisContext (vm.js:76:16)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3

I notice that async wasn't mentioned in package.json, nor was there any async = require("async"); anywhere

konsumer commented 5 years ago

async/await is built in to more modern versions of node (>=8). I could do it without (using just a promise) but also a node-upgrade should fix that, and is recommended. Current stable is 10.15.3, and the only reason to use older is when you really can't upgrade (Amazon Lambda uses 8.10, for example.)

The only file that needs to be moved is the inx file, which you already moved into your plugin directory, so we should be good on that. That's what makes it run, and hasn't changed since first release. It references inkscape-svgo, which should be in your path, after npm i -g inkscape-svgo (it should be correctly doing this, as you can run it manually in CLI.)

I am at a loss for troubleshooting steps. Locally the space in my username keeps it from working on Windows, and it seems like a problem with inkscape. This points me again to the idea of writing the CLI-parser in python, and distributing both together, but I hate that the instructions become more convoluted:

There has to be some simpler way.

konsumer commented 5 years ago

I will play with path stuff. maybe putting it in the same dir and calling it will help. it's not ideal, but may be a good in-between solution, just for windows.

konsumer commented 5 years ago

I played with various options for a bit and couldn't get anything to work.

I realized that I could use pkg to build a complete runtime+modules version, that's just an exe. It will make the plugin bigger, but then I can be sure it's the right node version, and paths are working right. I am fine with making this the way to use it for every platform, as it's a bit simpler if you aren't already a node 8+ user. I can simplify the instructions to "get the zip file for your platform and extract to your inkscape plugin dir" which is rad. I made #3 to track that. I'm going to work on this, and will let you know when I have it all setup.

konsumer commented 5 years ago

Ok, this should be resolved (follow new directions in README.) I will close the issue, but let me know if there are more issues.