Webpacker:compile freezes on "compile..."

This is the first time we are trying to run tests with webpacker compiling Vuejs app. The build freezes on the webpacker:compile step and then times out with this message:
Too long with no output (exceeded 35m0s)Too long with no output (exceeded 35m0s)

Default timeout was 10 minutes, we thought maybe that wasn’t enough and increased it to 35mins, and it still fails. On localhost it takes less than 20 seconds to compile with NODE_ENV=test and RAILS_ENV=test
We use rspec and capybara for tests.

We run webpacker on heroku successfully, although the compile time is long(6-7 minutes), it still finishes. Has anybody had this or similar issues? Pls help to resolve.

Rails 4.2.10
webpacker 4.0.7

circleci config:

version: 2
jobs:
  build:
    working_directory: ~/judgeme/judgeme
    parallelism: 1
    shell: /bin/bash --login
    environment:
      RAILS_ENV: test
      RACK_ENV: test
      NODE_ENV: test
     #some other variables in here
    docker:
      - image: circleci/ruby:2.4.4-node-browsers
    environment: # environment variables for primary container
      BUNDLE_JOBS: 3
      BUNDLE_RETRY: 3
      BUNDLE_PATH: vendor/bundle
      PGHOST: 127.0.0.1
      PGUSER: judgeme-test
      RAILS_ENV: test
  - image: circleci/postgres:9.5-alpine-ram # database image
    environment: # environment variables for database
      POSTGRES_USER: judgeme-test
      POSTGRES_DB: judgeme_test
      POSTGRES_PASSWORD: ""
  - image: redis
  - image: docker.elastic.co/elasticsearch/elasticsearch:6.0.1
steps:
  - checkout
  - run: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS

  # Restore bundle cache
  - restore_cache:
      keys:
        # - rails-demo-bundle-v2-{{ checksum "Gemfile.lock" }}
        - rails-demo-bundle-v2-{{ checksum "Gemfile.lock" }}
        # This branch if available
        - v1-dep-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
        # Default branch if not
        - v1-dep-master-{{ checksum "Gemfile.lock" }}
        # Any branch if there are none on the default branch - this should be unnecessary if you have your default branch configured correctly
        - v1-dep-{{ checksum "Gemfile.lock" }}

  - run:
      name: Bundle gems
      command: 'bundle check --path=vendor/bundle || bundle install --path=vendor/bundle'

  # Store bundle cache
  - save_cache:
      # key: rails-demo-bundle-v2-{{ checksum "Gemfile.lock" }}
      key: v1-dep-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
      paths:
      # This is a broad list of cache paths to include many possible development environments
      # You can probably delete some of these entries
      - vendor/bundle
      - ~/virtualenvs
      - ~/.bundle

  - run:
      name: Wait for DB
      command: dockerize -wait tcp://localhost:5432 -timeout 1m
  - run:
      name: Wait for ElasticSearch
      command: dockerize -wait tcp://127.0.0.1:9200/ -timeout 1m

  - run:
      name: Database setup
      command: bundle exec rake db:schema:load --trace

  - restore_cache:
      keys:
        - yarn-{{ checksum "yarn.lock" }}

  - run:
      name: Yarn install
      command: yarn install --cache-folder ~/.cache/yarn

    # save yarn cache
  - save_cache:
      key: yarn-{{ checksum "yarn.lock" }}
      paths:
        - ~/.cache/yarn

  - restore_cache:
      keys:
        - webpack-{{ .Revision }}

  - run:
      name: Compile webpacker assets
      command: bundle exec rake webpacker:compile
      no_output_timeout: 35m

  - save_cache:
      key: webpack-{{ .Revision }}
      paths:
        - /home/circleci/project/public/packs-test/

  - run:
      name: Run rspec with integrations tests at last
      command: |
        bundle exec rspec --profile 10 --format progress \
                          spec/controllers \
                          spec/jobs \
                          spec/mailers \
                          spec/models \
                          spec/policies \
                          spec/queries \
                          spec/services \
                          spec/integrations \
                          spec
      no_output_timeout: 3600s

  # Save test results for timing analysis
  - store_test_results:
      path: test_results
  - store_test_results:
      path: /tmp/circleci-test-results
  # Save artifacts
  - store_artifacts:
      path: /tmp/circleci-artifacts
  - store_artifacts:
      path: /tmp/circleci-test-results

Webpacker.yml:

default: &default
  source_path: app/javascript
  source_entry_path: packs
  public_root_path: public
  public_output_path: packs
  cache_path: tmp/cache/webpacker
  check_yarn_integrity: false
  webpack_compile_output: false

  # Additional paths webpack should lookup modules
  # ['app/assets', 'engine/foo/app/assets']
  resolved_paths: []

  # Reload manifest.json on all requests so we reload latest compiled packs
  cache_manifest: false

  # Extract and emit a css file
  extract_css: false

  static_assets_extensions:
    - .jpg
    - .jpeg
    - .png
    - .gif
    - .tiff
    - .ico
    - .svg
    - .eot
    - .otf
    - .ttf
    - .woff
    - .woff2

  extensions:
    - .erb
    - .vue
    - .mjs
    - .js
    - .sass
    - .scss
    - .css
    - .module.sass
    - .module.scss
    - .module.css
    - .png
    - .svg
    - .gif
    - .jpeg
    - .jpg

development:
  <<: *default
  compile: true

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

  # Reference: https://webpack.js.org/configuration/dev-server/
  dev_server:
    https: false
    host: localhost
    port: 3035
    public: localhost:3035
    hmr: false
    # Inline should be set to true if using HMR
    inline: true
    overlay: true
    compress: true
    disable_host_check: true
    use_local_ip: false
    quiet: false
    headers:
      'Access-Control-Allow-Origin': '*'
    watch_options:
      ignored: '**/node_modules/**'


test:
  <<: *default
  compile: false

  # Compile test packs to a separate directory
  public_output_path: packs-test

production:
  <<: *default

  # Production depends on precompilation of packs prior to booting for performance.
  compile: false

  # Extract and emit a css file
  extract_css: true

  # Cache manifest.json for performance
  cache_manifest: true

Found the solution to freezing compile in here
There is some issue in the interaction between erb-loader and spring.

However, now there is a different problem. Once the tests start running, elasticsearch container exits with code 137. I googled the problem. People say it has to do with container using too much resources and suggest to limit elasticsearch container heap allocation:
- image: docker.elastic.co/elasticsearch/elasticsearch:6.0.1
environment:
ES_JAVA_OPTS: -Xms250m -Xmx250m

This did not work for me.

This problem did not happen before we started using webpacker. I don’t know how they are related. If somebody experienced similar issues, pls help to resolve.