我完成了一个网站建设,并希望将其部署到Digital Ocean VPN。安装了Capistrano和乘客。在初始部署期间,我收到的错误显然与预编译资产有关,所以我尝试了#34; rake assets:precompile --trace RAILS_ENV = production"在我的rails生产环境本地,该过程中止此消息:" JSON :: GeneratorError:源序列非法/格式错误utf-8" 任何人都可以帮助我,我似乎无法解决这个问题。
> 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
答案 0 :(得分:3)
我遇到了完全相同的错误消息。有了这个说法,我用Google搜索&#34;检查文件是否有效utf-8&#34;并找到了isutf8(1): check whether files are valid UTF-8 - Linux man page。所以我安装了isutf8,然后从我的linux机器上的Rails根目录运行以下命令
isutf8 `find app`
虽然输出中有很多噪音,但它告诉我app/assets/javascripts/filterbar.js: line 1, char 1, byte offset 41: invalid UTF-8 code
。所以我打开了那个文件。中提琴!我看到一些乱码。删除这些字符后,rake assets:precompile
成功了。当然,你的实际有罪文件可能会有所不同。您还可以使用其他实用程序来检查utf-8,例如在this stackoverflow question on utf-8中。