The rake is interrupted! JSON :: GeneratorError: original sequence is illegal / incorrect utf-8 version after using rake assets: precompile

I have finished building a website and want to deploy to Digital Ocean VPN. Installed Capistrano and passenger. During initial deployment, I was getting an error that seemed to have something to do with precompiling assets, so I tried "rake assets: precompile --trace RAILS_ENV = production" in my rails work environment locally and the process is aborted with this message: "JSON :: GeneratorError: original sequence is illegal / incorrect utf-8 version" Can anyone help me with this, I can't seem to fix it.

> rake aborted! JSON::GeneratorError: source sequence is
> illegal/malformed utf-8
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/json-1.8.3/lib/json/common.rb:223:in
> `generate'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/json-1.8.3/lib/json/common.rb:223:in
> `generate'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/execjs-2.5.2/lib/execjs/external_runtime.rb:46:in
> `call'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/uglifier-2.7.1/lib/uglifier.rb:212:in
> `run_uglifyjs'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/uglifier-2.7.1/lib/uglifier.rb:179:in
> `compile'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/uglifier_compressor.rb:52:in `call'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/uglifier_compressor.rb:28:in `call'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/processor_utils.rb:75:in
> `call_processor'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/processor_utils.rb:57:in
> `block in call_processors'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/processor_utils.rb:56:in
> `reverse_each'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/processor_utils.rb:56:in
> `call_processors'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/loader.rb:86:in
> `load_asset_by_uri'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/loader.rb:45:in
> `block in load'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/loader.rb:155:in
> `fetch_asset_from_dependency_cache'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/loader.rb:38:in
> `load'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/cached_environment.rb:20:in
> `block in initialize'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/cached_environment.rb:47:in
> `yield'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/cached_environment.rb:47:in
> `load'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/base.rb:63:in
> `find_asset'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/base.rb:70:in
> `find_all_linked_assets'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/manifest.rb:138:in
> `block in find'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/legacy.rb:114:in
> `block (2 levels) in logical_paths'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:223:in
> `block in stat_tree'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:207:in
> `block in stat_directory'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:204:in
> `each'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:204:in
> `stat_directory'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:222:in
> `stat_tree'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/legacy.rb:105:in
> `each'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/legacy.rb:105:in
> `block in logical_paths'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/legacy.rb:104:in
> `each'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/legacy.rb:104:in
> `logical_paths'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/manifest.rb:136:in
> `find'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/manifest.rb:162:in
> `compile'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-rails-2.3.1/lib/sprockets/rails/task.rb:70:in
> `block (3 levels) in define'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/rake/sprocketstask.rb:147:in
> `with_logger'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-rails-2.3.1/lib/sprockets/rails/task.rb:69:in
> `block (2 levels) in define'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:240:in
> `call'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:240:in
> `block in execute'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:235:in
> `each'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:235:in
> `execute'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:179:in
> `block in invoke_with_call_chain'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/monitor.rb:211:in
> `mon_synchronize'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:172:in
> `invoke_with_call_chain'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:165:in
> `invoke'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:150:in
> `invoke_task'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:106:in
> `block (2 levels) in top_level'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:106:in
> `each'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:106:in
> `block in top_level'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:115:in
> `run_with_threads'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:100:in
> `top_level'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:78:in
> `block in run'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:176:in
> `standard_exception_handling'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:75:in
> `run' /Users/franco/.rvm/rubies/ruby-2.2.2/bin/rake:33:in `<main>'
> Tasks: TOP => assets:precompile

      

+3


source to share


1 answer


I came across the same error message. With this checklist, I googled "check if file is valid utf-8" and found isutf8 (1): check if files are valid UTF-8 - Linux man page . So I installed isutf8 and then ran the following command from the Rails root on my Linux machine.

isutf8 `find app`

      



Although there is a lot of noise coming out, he tells me that app/assets/javascripts/filterbar.js: line 1, char 1, byte offset 41: invalid UTF-8 code

. So I opened this file. Viola! I saw several distorted characters. Once I removed those characters, I was able to execute rake assets:precompile

. Of course, the actual file of your fault may be different. You can also use another utility to check for utf-8, like this stack question for utf-8 of course.

+3


source







All Articles