Use Rails 5.1 with Webpacker gem

rails
nodejs
ruby
2.0

#1

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 https://nodejs.org/en/download/

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

Here is the config.yml:

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

    steps:
      - 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
            bin/yarn
      - save_cache:
          key: dependency-cache-{{ checksum "Gemfile.lock" }}
          paths:
            - vendor/bundle
      - run:
          name: Create DB
          command: |
            cp config/database.yml.ci 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


#2

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.

https://circleci.com/docs/2.0/circleci-images/#ruby

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


#3

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


#4

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

#5

Did you get this to work?


#6

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


#7

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