webpacker: Railtie yarn check --integrity fails running in development under docker

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:

  1. Create a new Rails 5.2 application, specifying --webpack (other options used in example to reduce the number of moving parts)
$ 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
  1. Add .dockerignore, Dockerfile, .env.docker and docker-compose.yml files as per this gist: https://gist.github.com/sauy7/d5c732faad876fde8b2d16672b29a992

  2. 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.
  1. Wait for Rails to try to fully start up.

  2. Observe in server output:

========================================
  Your Yarn packages are out of date!
  Please run `yarn install` to update.
========================================
  1. Note in config/environments/development.rb:

    config.webpacker.check_yarn_integrity = true

  2. Edit to:

    config.webpacker.check_yarn_integrity = false

  3. Re-run:

    docker-compose up --build

  4. Browse to http://localhost:3000 to see the default Rails home page.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 35
  • Comments: 31 (2 by maintainers)

Most upvoted comments

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. 🤦‍♂️

The integrity failure comes because docker compose ignores .dockerignore for volume mount, which includes node_modules.

  • When creating a new Rails application and run yarn install, a node_modules folder is created according to the host environment.
  • And for the first time to run 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'

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

@mhbsti None, other than running with config.webpacker.check_yarn_integrity = false in development.rb as a workaround.

@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.

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.

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.

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.

Thanks @zhengpd! Your suggestion worked with rails 5.2.4.1, docker 19.03.8, and yarn 1.17.3.

~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.

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:

  • Delete node_modules before building (also delete relevant volumes, eg docker-compose down && docker volume prune)
  • If already on linux-x64, use matching node versions