1
0

More than 1 year has passed since last update.

【Rails6 & Docker】yarnのバージョンが古いとエラーが出た場合にしたこと

Posted at

Dockerでrails6の環境を構築した。

以下の記述でrails6の環境を立ち上げました

# Dockerfile
FROM ruby:2.6.5

RUN apt-get update && apt-get install -y sqlite3 build-essential libsqlite3-dev
RUN curl https://deb.nodesource.com/setup_18.x | bash
RUN curl https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list

RUN apt update && apt install -y nodejs yarn

RUN mkdir /app_name 

ENV APP_ROOT /app_name 
WORKDIR $APP_ROOT

ADD ./Gemfile $APP_ROOT/Gemfile
ADD ./Gemfile.lock $APP_ROOT/Gemfile.lock

RUN bundle install
RUN rails webpacker:install
RUN rails webpacker:compile
RUN rails db:migrate
ADD . $APP_ROOT
# docker-compose.yml
version: '3'
services:
  web:
    build: .
    command: /bin/sh -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    # docker-compose killとかでコンテナ終了させたとき、pidファイルが残っているので削除
    stdin_open: true
    tty: true
    # 上記二文にてbyebugを実行する設定
    # stdin_open:標準入力への接続を表す。
    # tty:標準出力の接続を表す。
    volumes:
      - .:/app_name
    ports:
      - "3000:3000"

docker-compose build 実行完了後 docker-compose up でサーバーを立ち上げようとするとエラーが発生しました。

error Couldn't find an integrity file                                                        
error Found 1 errors.                                                                        


========================================
  Your Yarn packages are out of date!
  Please run `yarn install --check-files` to update.
========================================


To disable this check, please change `check_yarn_integrity`
to `false` in your webpacker config file (config/webpacker.yml).


yarn check v1.22.19
info Visit https://yarnpkg.com/en/docs/cli/check for documentation about this command.

翻訳してみるとYarnのバージョンが古くなっているらしいので以下のコマンドでアップデートしました。

yarn install # 自分はdockerなので "docker-compose run web yarn install"で実行

実行後、インストールは正しく行えたが、その後のbuildでエラーが発生

~省略~
make: *** [binding.target.mk:133: Release/obj.target/binding/src/binding.o] Error 1
make: Leaving directory '/app_name/node_modules/node-sass/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/app_name/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:291:12)
gyp ERR! System Linux 5.10.16.3-microsoft-standard-WSL2
gyp ERR! command "/usr/bin/node" "/app_name/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /app_name/node_modules/node-sass
gyp ERR! node -v v18.12.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 

初めて出るエラーがだったので、検索してみた結果以下のサイトがヒットしました。
https://blog.furu07yu.com/entry/yarn-gyp-err

どうやら、下から4行目にあるようにnode-sassのバージョンに関する問題でエラーが発生している模様
そのため、サイト様に書かれているように"packerage.json"に書かれている@rails/webpackerのバージョンを修正したところ無事解消されました。

"@rails/webpacker": "^5.4.3",

また、gemとバージョンは合わせた方が良いかと考えGemfileに記載されているwebpackerのバージョンも更新しました。

gem 'webpacker', '~> 5.0'
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