似乎无法理解这一点,尝试运行任何脚本时我都会遇到以下错误:invalid byte sequence in UTF-8 (ArgumentError)
我有一台新的OSX机器,一切都很新鲜,使用Ruby 1.9.3和Rails 3.2.1,我已经开发了好几天,没有遇到任何问题。
我今天离开了几个小时,现在我无法运行任何脚本。
我第一次在尝试新的迁移时遇到错误,认为这是Postgres的问题,重新安装后,确保所有表都用UTF-8编码。
我还重新安装了RVM和Rails。
我认为如果必须使用数据库,调试会更容易,但我已经创建了新的应用程序,甚至无法启动服务器,收到了同样的错误。
全栈尝试在sqlite3
上的新应用程序中运行服务器
/Users/mgaughan/.rvm/gems/ruby-1.9.3-p0@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:136:in `split': invalid byte sequence in UTF-8 (ArgumentError)
from /Users/mgaughan/.rvm/gems/ruby-1.9.3-p0@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:136:in `setup_environment'
from /Users/mgaughan/.rvm/gems/ruby-1.9.3-p0@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:13:in `setup'
from /Users/mgaughan/.rvm/gems/ruby-1.9.3-p0@global/gems/bundler-1.0.21/lib/bundler.rb:110:in `setup'
from /Users/mgaughan/.rvm/gems/ruby-1.9.3-p0@global/gems/bundler-1.0.21/lib/bundler/setup.rb:7:in `'
from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `require'
from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `rescue in require'
from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from /Users/mgaughan/Code/something/config/boot.rb:6:in `'
from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from script/rails:5:in `'
现在,我越看越清楚,postgresql显然出了问题,因为在postgresql上的应用程序中,bundle无法安装pg
堆栈跟踪:
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/bin/ruby extconf.rb
checking for pg_config... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
/Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:1357:in `split': invalid byte sequence in UTF-8 (ArgumentError)
from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:1357:in `find_executable0'
from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:1384:in `block in find_executable'
from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:1383:in `find_executable'
from extconf.rb:27:in `'
Gem files will remain installed in /Users/mgaughan/.rvm/gems/ruby-1.9.3-p0/gems/pg-0.12.2 for inspection.
Results logged to /Users/mgaughan/.rvm/gems/ruby-1.9.3-p0/gems/pg-0.12.2/ext/gem_make.out
An error occured while installing pg (0.12.2), and Bundler cannot continue.
Make sure that `gem install pg -v '0.12.2'` succeeds before bundling.
它提到要检查的mkmf.log文件为空。
所以我猜测Postgresql可能是这个问题的根源,但我很困惑为什么使用sqlite3的新应用程序仍然会抛出这个字节错误。
任何帮助都将不胜感激,如果我能提供更多信息,请告诉我。
编辑
这个问题似乎已经自行解决了。
我对我的机器所做的唯一改变是按照@张的建议;我从Path中删除了一个sbin文件夹,该文件夹来自已卸载的旧NGINX安装。
也许这就是区别,但对我来说似乎不太可能
不管怎样,我执行了一个命令,一切都很好,已经好几天了。
根据stacktrace判断,PATH
环境变量包含一些令人不快的数据。我会先检查它,然后删除任何看起来不属于它的东西
您的初始化程序或环境配置(application.rb、development.rb等)是否包含无效字符?
如果您从网络上获取了一个javascript文件,该文件的头中有一些时髦的字符,则通常会发生这种情况。如果你把它包含在application.js中,Sprockets解析器就会对它产生不稳定的影响
在这种情况下,它看起来像是当你试图运行你的应用程序时,所以它向我表明,它是初始化过程中使用的一个文件中的无效字符。