Software versions:
Docker for Mac: 18.03.1-ce-mac65 (24312)
ruby: 2.5.1
rails: 5.2.0
webpacker: 3.5.3
Expected behaviour:
I would expect a new containerised Rails 5.2 application to pass the yarn integrity check when starting the application.
Note: Running puma -C config/puma.rb natively on the host Mac OS X does not trigger this issue.
Actual behaviour:
Same error as reported in #1374. When running the rails development server:
========================================
Your Yarn packages are out of date!
Please run `yarn install` to update.
========================================
Steps to reproduce:
$ rails new webpacker-example --webpack --skip-active-record --skip-action-mailer --skip-active-storage --skip-action-cable --skip-turbolinks --skip-test --skip-system-test --no-rc
$ cd webpacker-example
$ yarn install
Add .dockerignore, Dockerfile, .env.docker and docker-compose.yml files as per this gist:
https://gist.github.com/sauy7/d5c732faad876fde8b2d16672b29a992
Run:
docker-compose up --build
Note in the output that:
RUN yarn check --integrity
shows:
yarn check v1.7.0
success Folder in sync.
Done in 0.XXs.
Wait for Rails to try to fully start up.
Observe in server output:
========================================
Your Yarn packages are out of date!
Please run `yarn install` to update.
========================================
Note in config/environments/development.rb:
config.webpacker.check_yarn_integrity = true
Edit to:
config.webpacker.check_yarn_integrity = false
Re-run:
docker-compose up --build
Browse to http://localhost:3000 to see the default Rails home page.
Hi. I have the same problem.
@sauy7 , got any solutions?
Thanks.
@mhbsti None, other than running with config.webpacker.check_yarn_integrity = false in development.rb as a workaround.
Thank you @sauy7 . If my find any public solution here.
Same problem here, but outside Docker
Same problem, deploying to Heroku
Same problem with running rails in my docker local development.
Seems like the problem are different bindings for node-sass (and possibly other packages that depend on native libs).
docker exec container yarn check --integrity fails for me with the message "warning Integrity check: Linked modules don't match".
ls node_modules/node-sass/vendor
linux-x64-67
docker exec container ls node_modules/node-sass/vendor/
linux-x64-64
linux-x64-67
Edit: Possible workarounds:
node_modules before building (also delete relevant volumes, eg docker-compose down && docker volume prune)linux-x64, use matching node versionssame problem outside docker
:+1: same on dev without docker
What have people done to solve this. It literally _just_ showed up today and I have no idea what I should do!
Try: docker-compose run <service_name_here> yarn
I had this problem but config.webpacker.check_yarn_integrity = false didn't seem to fix it. For anyone else that's an idiot like me, the check_yarn_integrity config needs to be changed in config/environments/development.rb, not config/webpacker.yml. 🤦♂️
~I put /node_modules into .dockerignore file and the problem is gone. Not sure if this is a general solution.~
Edited: not a solution since docker compose ignores .dockerignore for volume mount. The problem gone by coincidence at that time.
The command it runs if you want to shell into the running container is yarn check --integrity && yarn check --verify-tree. I removed RUN ./bin/webpack from my Dockerfile and this error went away, but I'm confused as to why that would happen.
The integrity failure comes because docker compose ignores .dockerignore for volume mount, which includes node_modules.
yarn install, a node_modules folder is created according to the host environment.docker-compose up --build, the node_modules folder inside docker container would be overlaid by the one from host machine, because of the volume mount:volumes:
- '.:/usr/src/app'
Error occurs this time since the node modules are not for container environment.
After you run docker-compose run <service_name_here> yarn, the node_modules on host machine would be updated according to the container environment since yarn is run inside container. The error would be gone when trying docker-compose up --build again.
A solution could be to avoid node_modules overlay by using anonymous volume:
volumes:
- '.:/usr/src/app'
- '/usr/src/app/node_modules'
It still occurs with volume overlays is the baffling part. Our workflow also doesn't involve a local node install so there isn't a local ./app/node_modules folder anyways. Ended up disabling it because the later deployed version is installed with yarn install --frozen-lock and doesn't have any issues 🤷♂
volumes:
- ./app:/app:cached
- /app/node_modules
It still happens 😢
As @connorshea suggested removing the check_yarn_integrity in development fixed, but I don't think is the best way to go.
What are the down sides of setting config.webpacker.check_yarn_integrity = false in development? Assuming @zpdsky's explanation is correct, is this likely to lead to a situation where yarn on the host OS (e.g. macOS) installs JS modules that won't behave properly on the container OS, or vice versa?
@dmolesUC It often saved me already when running bin/webpacker or rails server with outdated dependencies, so in general it makes sense to have it enabled on development.
Any solutions???
Thanks @zhengpd! Your suggestion worked with rails 5.2.4.1, docker 19.03.8, and yarn 1.17.3.
What worked for me is not to COPY the yarn.lock to the image by Dockerfile.
yarn.lock must be generate after Dockerfile execute "RUN yarn install". Try remove yarn.lock from your project too and run the "docker-compose up --build" again.
@rafaeljcadena That seemed to do the trick!
What worked for me is not to COPY the yarn.lock to the image by Dockerfile.
yarn.lock must be generate after Dockerfile execute "RUN yarn install". Try remove yarn.lock from your project too and run the "docker-compose up --build" again.
But, then you install not the same Versions. Which may not be what you want.
What worked for me is not to COPY the yarn.lock to the image by Dockerfile.
yarn.lock must be generate after Dockerfile execute "RUN yarn install". Try remove yarn.lock from your project too and run the "docker-compose up --build" again.But, then you install not the same Versions. Which may not be what you want.
Yes, you can't guarantee the exactly version as in yarn.lock, but in package.json you have the lib versions with safe range.
thanks. i love you
Trying @rafaelfranca suggestion did the trick, here's the end result for my Dockerfile
FROM ruby:2.6
LABEL maintainer="[email protected]"
# YARN repository
RUN curl -sS 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
# Convention to use update and install on same line to actually install new packages
# We also use the line separation to make this easier to change
RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \
nodejs \
yarn
COPY Gemfile* /usr/src/app/
COPY package.json /usr/src/app/
WORKDIR /usr/src/app
RUN bundle install
RUN yarn install
COPY yarn.lock /usr/src/app/
COPY . /usr/src/app/
CMD ["bin/rails", "s", "-b", "0.0.0.0"]
And the docker-compose:
version: '3'
services:
web:
build: .
ports:
- "3000:3000"
This also fails when deploying to production ended up modifying the image like this:
FROM ruby:2.6
LABEL maintainer="[email protected]"
# Allow apt to work with https-based sources
RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \
apt-transport-https
# Ensure we install an up-to-date version of Node
# see https://github.com/yarnpkg/yarn/issues/2888
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
# Ensure latest packages for Yarn
RUN curl -sS 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
# Convention to use update and install on same line to actually install new packages
# We also use the line separation to make this easier to change
RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \
nodejs \
yarn
COPY Gemfile* /usr/src/app/
COPY package.json /usr/src/app/
WORKDIR /usr/src/app
ENV BUNDLE_PATH /gems
RUN bundle install
COPY package.json yarn.lock ./
RUN yarn install --check-files
COPY . /usr/src/app/
CMD ["bin/rails", "s", "-b", "0.0.0.0"]
the workaround is the COPY package.json yarn.lock ./
and RUN yarn install --check-files
@sauy7 Can this issue be closed? The integrity check was removed in #2518
go for it
Most helpful comment
I had this problem but
config.webpacker.check_yarn_integrity = falsedidn't seem to fix it. For anyone else that's an idiot like me, thecheck_yarn_integrityconfig needs to be changed inconfig/environments/development.rb, notconfig/webpacker.yml. 🤦♂️