1
0

More than 3 years have passed since last update.

Shopify CLIでrails createしたらcannot load such file -- nokogiri/nokogiriのエラーが発生したがBundlerの設定を変更して対応できた

Posted at

Shopify CLIを使いたくてプロジェクトを作るほぼ最初からハマった。
Shopify CLIの問題では無いが次に同じようなことで時間を無駄にしないためにメモ。

環境

  • MacBook Pro (16-inch, 2019)
    • CPUはIntel Core i9
  • macOS Big Sur (11.5.2)
  • Shopify CLI 2.2.2
    • Homebrewでインストールできる最新版 (2021/08/25 現在)
  • Ruby 2.6.3 (OS標準)
    • Bundler 1.17.2
  • Node.js / Yarnは多分動けば大丈夫だと思う (が一応バージョンも記載)
    • Node.js 14.17.0
    • Yarn 1.22.10

普段は rbenv を使ってプロジェクトに応じてRubyのバージョンを切り替えているが shopify rails create で何かしらエラーが出ていたのでとりあえずOS標準のRubyを使うようにしています。
Shopify CLIはHomebrewでインストール済みでShopifyにログイン済みであることから開始します。

エラー内容

% shopify rails create

上記コマンドを実行すると、アプリの名称や対応するDBを対話形式で入力しプロジェクトの初期化スクリプトが実行されます。

... (以下都度省略
┃          run  bundle install
┃ Ignoring nokogumbo-2.0.5 because its extensions are not built. Try: gem pristine nokogumbo --version 2.0.5
┃ Ignoring shopify-cli-2.2.2 because its extensions are not built. Try: gem pristine shopify-cli --version 2.2.2
┃ Fetching gem metadata from https://rubygems.org/............
┃ Resolving dependencies......

...

┃ Using nokogiri 1.12.3 (x86_64-darwin)
┃ Using nokogiri 1.12.3 (arm64-darwin)

...

┃ Bundle complete! 15 Gemfile dependencies, 72 gems now installed.
┃ Use `bundle info [gemname]` to see where a bundled gem is installed.
┃          run  bundle binstubs bundler
┃        rails  webpacker:install
┃ rails aborted!
┃ LoadError: cannot load such file -- nokogiri/nokogiri

...

┃ Caused by:
┃ LoadError: dlopen(/usr/local/Cellar/shopify-cli/2.2.2/gems/nokogiri-1.12.3-arm64-darwin/lib/nokogiri/2.6/nokogiri.bundle, 0x0009): could not use '/usr/local/Cellar/shopify-cli/2.2.2/gems/nokogiri-1.12.3-arm64-darwin/lib/nokogiri/2.6/nokogiri.bundle' because it is not a compatible arch - /usr/local/Cellar/shopify-cli/2.2.2/gems/nokogiri-1.12.3-arm64-darwin/lib/nokogiri/2.6/nokogiri.bundle

...

┗━━━━━━
✗ System call failed: /usr/local/Cellar/shopify-cli/2.2.2/bin/rails new --skip-spring --database=mysql __PROJECTNAME__

Nokogiriのインストールがうまくいかないっぽい。

対応

参考にさせていただいたサイトでNokogiri 1.11.0からmacOSでもプリコンパイル済みで配布されるようになったとの情報を見つけました。
今回使用するNokogiriのバージョンが1.12.3でプリコンパイル済みのものでは無いものを使用しようとしてエラーになっているようです。

プリコンパイル済みのものを使用するにはBundlerに設定が必要で Bundler 2.0 以下ではこのように設定しました。

% bundle config force_ruby_platform true

# Bundler 2.1以上は公式サイトの内容を参照

その上で、再度 shopify rails create でプロジェクトの雛形を作成します。

...

┃ Ignoring nokogumbo-2.0.5 because its extensions are not built. Try: gem pristine nokogumbo --version 2.0.5
┃ Ignoring shopify-cli-2.2.2 because its extensions are not built. Try: gem pristine shopify-cli --version 2.2.2
┃ Fetching gem metadata from https://rubygems.org/............
┃ Resolving dependencies....

...

┃ Using nokogiri 1.12.3

...

┃ Bundle complete! 15 Gemfile dependencies, 72 gems now installed.
┃ Use `bundle info [gemname]` to see where a bundled gem is installed.
┃          run  bundle binstubs bundler
┃        rails  webpacker:install
┃       create  config/webpacker.yml
┃ Copying webpack core config

... (ry

ログ状は正常終了しました。

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0