Guard or guard-uglify throwing an error won't rerun

房东的猫 提交于 2020-01-01 21:51:14

问题


Just started running Guard and I had a weird problem. As soon as I add in more than one file to concat and uglify---the uglifier keeps firing. I have to hit ^C to get it to stop and that throws the following error:

 ERROR - Guard::Uglify failed to achieve its <run_on_change>, exception was:
 ExecJS::RuntimeError: 
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:142:in `exec_runtime'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:28:in `block in exec'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:41:in `compile_to_tempfile'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:27:in `exec'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/uglifier-1.3.0/lib/uglifier.rb:100:in `compile'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-uglify-0.1.0/lib/guard/uglify.rb:23:in `run_on_change'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:99:in `block in run_supervised_task'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:97:in `catch'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:97:in `run_supervised_task'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:146:in `block in run_first_task_found'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:144:in `each'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:144:in `run_first_task_found'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:79:in `block in run_on_changes'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:175:in `block (3 levels) in scoped_guards'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:174:in `each'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:174:in `block (2 levels) in scoped_guards'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:173:in `catch'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:173:in `block in scoped_guards'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:172:in `each'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:172:in `scoped_guards'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:72:in `run_on_changes'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard.rb:141:in `block (2 levels) in setup_listener'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard.rb:365:in `block in within_preserved_state'
 <internal:prelude>:10:in `synchronize'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard.rb:362:in `within_preserved_state'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard.rb:140:in `block in setup_listener'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/listen-0.7.3/lib/listen/listener.rb:212:in `call'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/listen-0.7.3/lib/listen/listener.rb:212:in `on_change'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/listen-0.7.3/lib/listen/listener.rb:221:in `block in initialize_adapter'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/listen-0.7.3/lib/listen/adapter.rb:198:in `call'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/listen-0.7.3/lib/listen/adapter.rb:198:in `report_changes'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/listen-0.7.3/lib/listen/adapter.rb:210:in `poll_changed_dirs'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/listen-0.7.3/lib/listen/adapters/darwin.rb:38:in `block in start'

Mind you the code was still min'ed correctly and everything worked...BUT once I hit ^C uglify won't fire again. Like I said, I'm new to Guard so I have no idea if I'm doing something wrong, if this is a bug with guard-uglify or something with Ruby or just something with Guard itself.

Couple of notes:

  1. Yes, all gems are up to date
  2. Ruby 1.9.3
  3. Mac OSX 10.8.3

Also, here is my Guardfile:

guard :concat, type: "js", files: %w(vendor/jquery-1.9.1.min vendor/handlebars vendor/jquery.iosslider.min app), input_dir: "js", output: "js/s.min"

guard 'uglify', :destination_file => "js/s.min.js" do
  watch (%r{js/s.min.js})
end

Any help greatly appreciated


回答1:


The uglifier plugin is configured to write to the same file that it's watching for changes, creating an infinite loop. You need to use different files:

guard :concat, {
  type: 'js',
  files: %w(vendor/jquery-1.9.1.min vendor/handlebars vendor/jquery.iosslider.min app),
  input_dir: 'js',
  output: 'js/s'
}

guard 'uglify', :destination_file => 'js/s.min.js' do
  watch (%r{js/s.js})
end

Edit

Since a subsequent error has been reported, I had a look at the plugin and recognized that is has been updated, but no new gem has been pushed to RubyGems. So it looks like the creation lost interest in the plugin. You can fetch the latest plugin directly from GitHub by changing the Gemfile:

gem 'guard-uglify', github: 'pferdefleisch/guard-uglify'

This makes it work on my machine. To be honest I'd not have that unfinished and unmaintained plugin in my toolchain. You can achieve the same by using guard-jammit or guard-process.



来源:https://stackoverflow.com/questions/15929716/guard-or-guard-uglify-throwing-an-error-wont-rerun

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!