kamsar / Dianoga

An automatic image optimizer for the Sitecore media library.
Other
104 stars 45 forks source link

SVGO not working on Azure PaaS #46

Closed markgibbons25 closed 4 years ago

markgibbons25 commented 5 years ago

I have Sitecore 9.0.1 on Azure PaaS with Dianoga 4.0.0, PNG and JPG optimisation works, but getting this exception on all SVG's.

40632 00:26:40 ERROR Dianoga: Unable to optimize /Project/xxx/Public/xxx/Icons/ico-twitter due to a processing error! It will be unchanged. Exception: System.InvalidOperationException Message: D:\home\site\wwwroot\App_Data\Dianoga Tools\SVGO\node.exe exited with unexpected exit code 1. Output: at Module.require (module.js:353:17) at Function.Module._load (module.js:300:12) at Module.load (module.js:343:32) at Object.Module._extensions..js (module.js:416:10) at Module._compile (module.js:409:26) at Object. (D:\home\site\wwwroot\App_Data\Dianoga Tools\SVGO\node_modules\svgo\node_modules\colors\lib\colors.js:176:23) at require (internal/module.js:12:17) at Module.require (module.js:353:17) at Function.Module._load (module.js:276:25) at Function.Module._resolveFilename (module.js:325:15) Error: Cannot find module './maps/rainbow'

^
throw err;

module.js:327

Source: Dianoga at Dianoga.Optimizers.CommandLineToolOptimizer.ExecuteProcess(String arguments) at Dianoga.Optimizers.CommandLineToolOptimizer.ProcessOptimizer(OptimizerArgs args) at Dianoga.Optimizers.OptimizerProcessor.Process(OptimizerArgs args) at (Object , Object[] ) at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) at Dianoga.Processors.Pipelines.DianogaOptimize.ExtensionBasedOptimizer.ProcessOptimize(ProcessorArgs args) at (Object , Object[] ) at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) at Dianoga.MediaOptimizer.Process(MediaStream stream, MediaOptions options)

I have confirmed that the maps/rainbow.js file is being deployed. I have confirmed that it is using the nodejs.exe in the App_Data\Dianoga Tools\SVGO\node.exe by checking the kudu console.

Thanks in advance!

kamsar commented 5 years ago

It sounds like the working directory may be incorrect or otherwise messing up node module resolution. I don't have a particular fix in mind, but you could try using https://www.npmjs.com/package/pkg (or this pre-packed but older release of svgop) as a command line invocation: https://github.com/twardoch/svgop

In the specific case of Azure, you might also be running into some sort of limitation on running executables. App Service has Node installed (you may need to upgrade the version), and you could consider invoking that system level Node on svgo instead.

If you figure out a workaround, I'd merge a PR to fix it.

markgibbons25 commented 4 years ago

Retested with 5.0 RC 4. Interestingly, it worked for about half the svg's on the page, other half various issues with timeouts and this error:

7244 22:37:53 ERROR Dianoga: Unable to optimize /Themes//images/icons/ico-search-white due to a processing error! It will be unchanged.
Exception: System.InvalidOperationException
Message: "D:\home\site\wwwroot\App_Data\Dianoga Tools\SVGO\node.exe "D:\home\site\wwwroot\App_Data\Dianoga Tools\SVGO\node_modules\svgo\bin\svgo" --input="D:\local\Temp\tmp7FC.tmp" --output="D:\local\Temp\tmp7FD.tmp" --disable=removeUselessDefs --disable=cleanupIDs" exited with unexpected exit code 1. Output: 
}
  ]
    'D:\\home\\site\\wwwroot\\App_Data\\Dianoga Tools\\SVGO\\node_modules\\svgo\\bin\\svgo'
    'D:\\home\\site\\wwwroot\\App_Data\\Dianoga Tools\\SVGO\\node_modules\\svgo\\lib\\svgo\\coa.js',
    'D:\\home\\site\\wwwroot\\App_Data\\Dianoga Tools\\SVGO\\node_modules\\svgo\\node_modules\\util.promisify\\index.js',
    'D:\\home\\site\\wwwroot\\App_Data\\Dianoga Tools\\SVGO\\node_modules\\svgo\\node_modules\\util.promisify\\implementation.js',
    'D:\\home\\site\\wwwroot\\App_Data\\Dianoga Tools\\SVGO\\node_modules\\svgo\\node_modules\\object.getownpropertydescriptors\\index.js',
    'D:\\home\\site\\wwwroot\\App_Data\\Dianoga Tools\\SVGO\\node_modules\\svgo\\node_modules\\object.getownpropertydescriptors\\implementation.js',
    'D:\\home\\site\\wwwroot\\App_Data\\Dianoga Tools\\SVGO\\node_modules\\svgo\\node_modules\\es-abstract\\2019\\CreateDataProperty.js',
    'D:\\home\\site\\wwwroot\\App_Data\\Dianoga Tools\\SVGO\\node_modules\\svgo\\node_modules\\es-abstract\\GetIntrinsic.js',
  requireStack: [
  code: 'MODULE_NOT_FOUND',
    at Module.require (internal/modules/cjs/loader.js:848:19) {
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Object.<anonymous> (D:\home\site\wwwroot\App_Data\Dianoga Tools\SVGO\node_modules\svgo\node_modules\es-abstract\GetIntrinsic.js:165:12)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Module.require (internal/modules/cjs/loader.js:848:19)
    at Function.Module._load (internal/modules/cjs/loader.js:686:27)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
- D:\home\site\wwwroot\App_Data\Dianoga Tools\SVGO\node_modules\svgo\bin\svgo
- D:\home\site\wwwroot\App_Data\Dianoga Tools\SVGO\node_modules\svgo\lib\svgo\coa.js
- D:\home\site\wwwroot\App_Data\Dianoga Tools\SVGO\node_modules\svgo\node_modules\util.promisify\index.js
- D:\home\site\wwwroot\App_Data\Dianoga Tools\SVGO\node_modules\svgo\node_modules\util.promisify\implementation.js
- D:\home\site\wwwroot\App_Data\Dianoga Tools\SVGO\node_modules\svgo\node_modules\object.getownpropertydescriptors\index.js
- D:\home\site\wwwroot\App_Data\Dianoga Tools\SVGO\node_modules\svgo\node_modules\object.getownpropertydescriptors\implementation.js
- D:\home\site\wwwroot\App_Data\Dianoga Tools\SVGO\node_modules\svgo\node_modules\es-abstract\2019\CreateDataProperty.js
- D:\home\site\wwwroot\App_Data\Dianoga Tools\SVGO\node_modules\svgo\node_modules\es-abstract\GetIntrinsic.js
Require stack:
Error: Cannot find module 'function-bind'

    ^
    throw err;
internal/modules/cjs/loader.js:796

Source: Dianoga
   at Dianoga.Optimizers.CommandLineToolOptimizer.ExecuteProcess(String arguments)
   at Dianoga.Optimizers.CommandLineToolOptimizer.ProcessOptimizer(OptimizerArgs args)
   at Dianoga.Optimizers.OptimizerProcessor.Process(OptimizerArgs args)
   at (Object , Object )
   at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
   at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists)
   at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain)
   at Dianoga.Processors.Pipelines.DianogaOptimize.ExtensionBasedOptimizer.ProcessOptimize(ProcessorArgs args)
   at (Object , Object )
   at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
   at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists)
   at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain)
   at Dianoga.MediaOptimizer.Process(MediaStream stream, MediaOptions options)
markgibbons25 commented 4 years ago

Changed to use https://github.com/twardoch/svgop which has resolved the issue.