Use Rails 5.1 with Webpacker gem



I have a Rails 5.1 app that’s using the new included webpacker gem for asset management, which is dependent on node.js and yarn.

At the step when I run bundle exec rake test, webpacker attempts to compile assets, and I get this error:

Node.js not installed. Please download and install Node.js

How do I run my tests with access to both Rails and Node?

Here is the config.yml:

version: 2
      - image: ruby:2.4.0
      - image: node:7.4.0
      - image: postgres:9.4.1
          POSTGRES_USER: root
          TZ: "/usr/share/zoneinfo/America/New_York"
    working_directory: ~/shadowfax-demo
      TZ: "/usr/share/zoneinfo/America/New_York"
      RAILS_ENV: test
      RACK_ENV: test

      - checkout
      - run:
          name: Install System Dependencies
          command: apt-get update -qq && apt-get install -y build-essential nodejs
      - restore_cache:
          key: dependency-cache-{{ checksum "Gemfile.lock" }}
      - run:
          name: Install Dependencies
          command: |
            apt-get install -y libicu52 && apt-get install -y libicu-dev
            bundle install --path vendor/bundle --frozen --jobs=4 --retry=3 --without development
      - save_cache:
          key: dependency-cache-{{ checksum "Gemfile.lock" }}
            - vendor/bundle
      - run:
          name: Create DB
          command: |
            cp config/ config/database.yml
            export RAILS_ENV="test"
            export RACK_ENV="test"
            bundle exec rake db:create db:schema:load --trace
      - run:
          name: Run Tests
          command: bundle exec rake test
      - run:
          name: Report coverage to CodeClimate
          command: bundle exec codeclimate-test-reporter
      - store_artifacts:
          path: coverage
          destination: coverage
      - store_test_results:
          path: /tmp/circle-junit


You can’t stack images like that to use Ruby and Node. Instead, you should use one of our CircleCI images. The Dockerfiles aren’t yet open sourced but you can use docker history <image> to see what commands were run.

You specifically want one of the node ones, and if you use Selenium at all, you’ll want a node-browsers image.


@rohara Thanks! I used circleci/ruby:2.4-node-browsers, but yarn was not installed. Are there any images with yarn preinstalled?


It is installed unless you change $PATH or something like that.

$ docker run -it circleci/ruby:2.4-node-browsers yarn --version
_XSERVTransmkdir: ERROR: euid != 0,directory /tmp/.X11-unix will not be created.


Did you get this to work?


Just reference it as /usr/local/bin/yarn if you’re having issues.


This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.