3
0

More than 3 years have passed since last update.

【エラー解決】The engine “node” is incompatible with this module

Posted at

【Rails6+Docker】で環境構築をし、ECサイトを作ろうとしています。

Railsがバージョン6以降のため下記コマンドでwebpackerをインストールしようとした際、エラーが発生したため、解決策を備忘録に残しておきます。

ターミナル
$ docker-compose run --rm app rails webpacker:install 
エラー文
error http-proxy-middleware@2.0.1: The engine "node" is incompatible with this module. Expected version ">=12.0.0". Got "10.24.1"
error Found incompatible module.

Node.js バージョン確認

①Dockerコンテナ上で動いている Node.js のバージョンを確認

ターミナル
$ docker-compose run --rm app node -v
v10.24.1

②ローカルの Node.js のバージョンを確認

ターミナル
$ node -v
v16.6.1

やっぱり・・・・。
ということは、Dockerコンテナ上で動いている Node.js のバージョンを12.0.0以上に変更すれば解決できるかもしれない。

そこで、Dockerfileでバージョン指定してみる。

元々のDockerfile
FROM ruby:3.0.0

RUN apt-get update -qq && \
    apt-get install -y build-essential libpq-dev nodejs vim

RUN apt-get update && apt-get install -y curl apt-transport-https wget && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && apt-get install -y yarn

RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
        && apt-get install -y nodejs

RUN mkdir -p /var/www/solidus

WORKDIR /var/www/solidus

ADD Gemfile /var/www/solidus/Gemfile
ADD Gemfile.lock /var/www/solidus/Gemfile.lock

RUN gem install bundler
RUN bundle install

ADD . /var/www/solidus

RUN mkdir -p tmp/sockets
RUN mkdir -p tmp/pids
バージョン指定後のDockerfile
# Dockerfile
FROM ruby:3.0.0

RUN apt-get update -qq && \
    apt-get install -y build-essential libpq-dev nodejs vim

RUN apt-get update && apt-get install -y curl apt-transport-https wget && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && apt-get install -y yarn

RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
        && apt-get install -y nodejs npm && npm install n -g && n 16.6.1

RUN mkdir -p /var/www/solidus

WORKDIR /var/www/solidus

ADD Gemfile /var/www/solidus/Gemfile
ADD Gemfile.lock /var/www/solidus/Gemfile.lock

RUN gem install bundler
RUN bundle install

ADD . /var/www/solidus

RUN mkdir -p tmp/sockets
RUN mkdir -p tmp/pids

上記のように変更し、変更を反映させるために$ docker-compose buildしてみる。

ターミナル
$ docker-compose build

しかし、バージョン指定が上手くいかず、エラー。。。

そこで反対にローカルのNode.js のバージョンをコンテナのNode.js のバージョンに合わせてみる。
まずは利用可能なバージョン一覧の確認から。

ターミナル
$ nodebrew ls-remote

[...]
v9.0.0    v9.1.0    v9.2.0    v9.2.1    v9.3.0    v9.4.0    v9.5.0    v9.6.0
v9.6.1    v9.7.0    v9.7.1    v9.8.0    v9.9.0    v9.10.0   v9.10.1   v9.11.0
v9.11.1   v9.11.2

v10.0.0   v10.1.0   v10.2.0   v10.2.1   v10.3.0   v10.4.0   v10.4.1   v10.5.0
v10.6.0   v10.7.0   v10.8.0   v10.9.0   v10.10.0  v10.11.0  v10.12.0  v10.13.0
v10.14.0  v10.14.1  v10.14.2  v10.15.0  v10.15.1  v10.15.2  v10.15.3  v10.16.0
v10.16.1  v10.16.2  v10.16.3  v10.17.0  v10.18.0  v10.18.1  v10.19.0  v10.20.0
v10.20.1  v10.21.0  v10.22.0  v10.22.1  v10.23.0  v10.23.1  v10.23.2  v10.23.3
v10.24.0  v10.24.1

v11.0.0   v11.1.0   v11.2.0   v11.3.0   v11.4.0   v11.5.0   v11.6.0   v11.7.0
v11.8.0   v11.9.0   v11.10.0  v11.10.1  v11.11.0  v11.12.0  v11.13.0  v11.14.0
v11.15.0

v12.0.0   v12.1.0   v12.2.0   v12.3.0   v12.3.1   v12.4.0   v12.5.0   v12.6.0
v12.7.0   v12.8.0   v12.8.1   v12.9.0   v12.9.1   v12.10.0  v12.11.0  v12.11.1
v12.12.0  v12.13.0  v12.13.1  v12.14.0  v12.14.1  v12.15.0  v12.16.0  v12.16.1
v12.16.2  v12.16.3  v12.17.0  v12.18.0  v12.18.1  v12.18.2  v12.18.3  v12.18.4
v12.19.0  v12.19.1  v12.20.0  v12.20.1  v12.20.2  v12.21.0  v12.22.0  v12.22.1
v12.22.2  v12.22.3  v12.22.4  v12.22.5
[...]

ローカルにインストール済みのバージョンを確認。

ターミナル
$ nodebrew ls


v16.6.1

current: v16.6.1

特定のバージョンのインストール。私はv10.24.1をインストールしたいので、下記実行。

ターミナル
nodebrew install-binary v10.24.1

再び、ローカルにインストール済みのバージョンを確認。

ターミナル
$ nodebrew ls

v10.24.1
v16.6.1

current: v16.6.1

無事インストールされた!
あとはバージョンの切り替えを行えばOK。

ターミナル
$ nodebrew use v10.24.1
use v10.24.1

最終確認。

ターミナル
$ node -v
v10.24.1

ではここで再びbuildし直してみる。

ターミナル
$ docker-compose build

build成功。
次は問題の$ docker-compose run --rm app rails webpacker:install。
果たして・・・

ターミナル
$ docker-compose run --rm app rails webpacker:install

駄目でした・・・m(_ _)m
そもそも、Expected version ">=12.0.0".というエラーだったのにv10.24.1にしても意味なかったです・・・(笑)

結局、Dockerfileのnodejsのバージョンを変えるしかないのですが、上記の通りruby3.0.0だと上手くいかなかったため、試行錯誤の末バージョンを2.7.1に下げて、下記のようにDockerfileとGemfileを変更したら成功しました!

Dockerfile
FROM ruby:2.7.1 #←ここ変更

RUN apt-get update -qq && \
    apt-get install -y build-essential libpq-dev nodejs vim

RUN apt-get update && apt-get install -y curl apt-transport-https wget && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && apt-get install -y yarn

RUN curl -sL https://deb.nodesource.com/setup_16.x | bash - && \ #←ここ変更
    apt-get install -y nodejs

RUN mkdir -p /var/www/solidus

WORKDIR /var/www/solidus

ADD Gemfile /var/www/solidus/Gemfile
ADD Gemfile.lock /var/www/solidus/Gemfile.lock

RUN gem install bundler
RUN bundle install

ADD . /var/www/solidus

RUN mkdir -p tmp/sockets
RUN mkdir -p tmp/pids
Gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.7.1' #←ここ変更

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.4'
# Use mysql as the database for Active Record
gem 'mysql2', '~> 0.5'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 5.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 4.1.0'
  # Display performance information such as SQL time and flame graphs for each request in your browser.
  # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
  gem 'rack-mini-profiler', '~> 2.0'
  gem 'listen', '~> 3.3'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 3.26'
  gem 'selenium-webdriver'
  # Easy installation and use of web drivers to run system tests with browsers
  gem 'webdrivers'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

▼参考にさせていただいた記事

3
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
3
0