2

I have a project that I recently migrate from rails 5.0 to rails 5.1, before this I had webpacker install and I deploy it with capistrano, in rails 5.0 everything was working, but when I did the change now capistrano is unable to finish the assets:precompile task and I get this error:

** DEPLOY FAILED ** Refer to log/capistrano.log for details. Here are the last 20 lines: ..... DEBUG [04ae7a64] Command: cd /home/deploy/my-site/releases/20170602233846 && ( export RAILS_ENV="staging" ; ~/.rvm/bin/rvm default do bundle exec rake assets:precompile )

DEBUG [04ae7a64] yarn install v0.24.5

DEBUG [04ae7a64] [1/4] Resolving packages...

DEBUG [04ae7a64] [2/4] Fetching packages...

DEBUG [04ae7a64] warning fsevents@1.1.1: The platform "linux" is incompatible with this module.

DEBUG [04ae7a64] info "fsevents@1.1.1" is an optional dependency and failed compatibility check. Excluding it from installation.

DEBUG [04ae7a64] [3/4] Linking dependencies...

DEBUG [04ae7a64] [4/4] Building fresh packages...

DEBUG [04ae7a64] Done in 9.29s.

I'm using a local computer with ubuntu and ubuntu also is installed in the server.

I don't know where fsevents@1.1.1 is required as a dependency but I'm unabled to make deploy since 2 days ago and I haven't found a solution.

Eduardo
  • 74
  • 1
  • 9

1 Answers1

3

EDIT: I think my original Webpacker installation must have gone wrong somehow. Using the master branch of webpacker and re-running bundle exec rake webpacker:install has fixed this issue.


Original Answer: I came across this same error today. I think ./bin/yarn install --no-progress which is what the Rails rake task naturally runs, must return a non-zero exit code.

Firstly I tried overriding the yarn:install rake task to add --ignore-optional but this didn't work.

I have got my deployment to succeed by adding the rake task lib/tasks/yarn.rake containing:

namespace :yarn do
  desc "Install all JavaScript dependencies as specified via Yarn"
  task :install do
    puts "Ignoring yarn install failure"

    begin
      system "./bin/yarn install --no-progress --ignore-optional; true"
    rescue
      exit(true)
    end

    exit(true)
  end
end

task(:default).clear.enhance(['yarn:install'])

# Run Yarn prior to Sprockets assets precompilation, so dependencies are available for use.
if Rake::Task.task_defined?("assets:precompile")
  Rake::Task["assets:precompile"].enhance [ "yarn:install" ]
end

This replaces Rails' default yarn install rake task to pretty much ensure any errors aren't caught by Capistrano. This isn't a good solution, but at least it gets the deployment to succeed. Hopefully a legitimate yarn install error would lead to another error later in the assets build.

cdyer
  • 1,220
  • 1
  • 12
  • 21