红宝石赛车错误错误:执行 gem 时...(NoMethodError) undefined 方法 'size' for nil:NilClass



在安装 therubyracer 以及 Ruby 2.0.0.p0 和 Rails 4.0 时,我收到以下错误

ERROR:  While executing gem ... (NoMethodError)
    undefined method `size' for nil:NilClass

如果我使用捆绑安装安装相同的 gem,则会出现依赖 gem 错误,请参阅下面的日志。

NoMethodError: undefined method `size' for nil:NilClass
An error occurred while installing libv8 (3.16.14.3), and Bundler cannot continue.
Make sure that `gem install libv8 -v '3.16.14.3'` succeeds before bundling.

请找到我尝试安装的 GIT 的链接https://github.com/niquola/angularjs-on-rails

我今天遇到了同样的问题。并解决了它。我使用的是Lubuntu 13.04,RVM和Ruby 1.9.3。

可能是您的平台不在 rubyracer 使用的 libv8 支持列表中,并且 gem 应该由您自己编译。

直接来自: https://github.com/cowboyd/libv8

从 git 获取 libv8 源代码,编译它并从以下位置构建 gem:

git clone git://github.com/cowboyd/libv8.git
cd libv8
bundle install
bundle exec rake checkout
bundle exec rake compile
bundle exec rake build

安装宝石:

gem install ./pkg/libv8-3.16.14.3.gem

在我的项目文件夹上执行"捆绑包更新"时,我仍然收到错误,因为 gem 似乎没有复制到我的捆绑包 gem 缓存中。

Bundler::GemspecError: Could not read gem at /home/devmachine/.rvm/gems/ruby-1.9.3-p448/cache/libv8-3.16.14.3.gem. It may be corrupted.
An error occurred while installing libv8 (3.16.14.3), and Bundler cannot continue.
Make sure that `gem install libv8 -v '3.16.14.3'` succeeds before bundling.

所以我在再次运行"捆绑包更新"之前将其复制到此文件夹:

cp /home/devmachine/Downloads/libv8/pkg/libv8-3.16.14.3.gem /home/devmachine/.rvm/gems/ruby-1.9.3-p448/cache

请记住,在执行编译之前,您应该安装以下软件包:

  • 吉特
  • git-svn
  • libv8-dev
  • G++

我希望它有所帮助。

- =

更好的解决方案 = -

实际上是RTFM的一个案例。

您不必使用本机扩展构建自己的 Gem。您只需要在系统中存在 v8 库即可。之后,您可以将捆绑器配置为使用本机 v8。为此,您应该在系统上安装 V8 引擎。

# Get Google v8 engine from git
git clone git://github.com/v8/v8.git v8 && cd v8
# Install GYP
make dependencies
# I had problems with warnings and strict aliasing. So I ignored and switched them off.
make native werror=no strictaliasing=off

现在您应该能够从系统使用 v8:

bundle config build.libv8 --with-system-v8

在此命令之后,您可以继续使用通常的"捆绑安装"。

- =

建议的解决方案 = -

忘记 v8 并使用 Node.js 代替:

wget http://nodejs.org/dist/node-latest.tar.gz
tar zxvf node-latest.tar.gz
# cd into extracted directory (e.g. cd node-v0.10.14)
make
make install

从项目 Gemfile 中删除"therubyracer"依赖项。

相关内容

最新更新