[RUBY] Please run `yarn install --check-files` to update.

It is a memorandum because I was addicted to the following error when using docker.

【environment】

・ Ruby 2.7.1 ・ Rails 6.0.3.4 ・ Docker

Dockerfile

FROM ruby:2.7.1
RUN 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 -qq \
    && apt-get install -y nodejs yarn \
    && mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
COPY . /myapp

COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

CMD ["rails", "server", "-b", "0.0.0.0"]

phenomenon

Clone the environment that has been uploaded to git in team development locally. There was a phenomenon that the docker container crashed when executing docker-compose up. When I checked the log, I found the following yarn error.

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).
* If you want to hurry to the conclusion, please scroll to the bottom. (Because it is long)

First, I will refer to the following article as a countermeasure for this error. We have adopted the following changes. https://qiita.com/KenAra/items/2708ce3d5c80c4f24920

config/webpacker.yml


# Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
check_yarn_integrity: false  #Changed not to check yarn

With this support, docker started → rails screen was also displayed.

スクリーンショット 2020-11-15 16.47.27.jpg

However, I was relieved for a while.

Model generation with Scaffold → rails db: migrate Alright, let's check the index screen ..

スクリーンショット 2020-11-09 15.02.32.jpg

As a countermeasure for this error, I referred to the following article and Issue. https://qiita.com/natecotus/items/a2bd9f3ebd5b1866d48e https://qiita.com/takuma_0625/items/2709f81ffa005fde2188 https://github.com/rails/webpacker/issues/2071

I entered Docker with docker-compose web bash and executed the following installation.

rails webpacker:install

Yes, the error was successfully resolved and I was able to check the rails screen again.

I tried to check the difference what was changed when the above command was executed.

config/webpacker.yml


# Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
check_yarn_integrity: true

That was all. And ... that? I'm back ...

What was changed when the yarn error was resolved? The cause of the first error has become a mystery. Furthermore, if I cloned again with only this coping method, I noticed that the problem of the first yarn was likely to recur, and I was worried, so I conducted a re-investigation.

Please refer to the following and clone again in another environment The following command was executed after "Webpacker :: Manifest :: MissingEntryError" occurred. https://qiita.com/ashketcham/items/48d64e960d436f8b6f78

$ docker-compose run --rm web yarn install 

→ Yes, the problem was solved here as well. Thank you, seniors.

Why was it solved by running $ rails webpacker: install? I understood it when I checked the log at runtime. When webpacker: install was executed, yarn install was also executed at the same time.

To the conclusion ... This workaround is because yarn install is done when docker-compose run Title of this case 「Please run yarn install --check-files to update.」 Before the occurrence of $ docker-compose run --rm web yarn install I wonder if there was no problem if I executed.

So → I recommitted and confirmed.

Conclusion

When the following error occurs in log without starting the container with docker-compose up

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

I was able to solve it by executing the following command (yarn install when docker is started).

$ docker-compose run --rm web yarn install

Causes and impressions

When I read it back. Yarn's package is old! I'm angry. It seems that it was only necessary to update the yarn package at the same time as image construction → startup with docker run.

that's all. Because the following two points were confirmed I guess that the execution result of yarn install is reflected in the process of making docker image. --Diff was not found in the files in the environment even after checking the diff before and after executing yarn install. --Occurs only when starting the cloned environment.

Recommended Posts

Please run `yarn install --check-files` to update.
[Docker] dokcer-compose run, Please run `yarn install –check-files` to update. Error
Install Webpacker and Yarn to run Rails
[Ruby on Rails] yarn install --check-files
How to install Docker
How to install docker-machine
How to install MySQL
How to install ngrok
How to run npm install on all projects in Lerna