首页 > 解决方案 > 无法运行资产:在heroku上预编译

问题描述

我正在 Rails 5.2.1 和 Ruby 2.4.4p296 下的 Windows 10 上开发 Rails 应用程序

我无法运行命令heroku run rake assets:precompile

我收到此错误:

C:\Users\Jaiel\Desktop\RubyOnRailsForum>heroku run rake assets:precompile --trace
Running rake assets:precompile --trace on ⬢ warm-mountain-15591... up, run.4644 (Free)
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke yarn:install (first_time)
** Execute yarn:install
Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
** Execute assets:precompile

甚至是错误吗?heroku上的文件夹中有资产public/assets,但是 JavaScript 文件似乎无法正常工作或相互冲突,因为我也遇到了问题。例如,method: :delete在生产环境中的 Heroku 上的我的应用程序中,与 don't work 的链接。

这是一个关于我的问题的线程,可能与它有关

标签: ruby-on-railsheroku

解决方案


尝试这个

 $rake assets:precompile (RAILS_ENV=production bundle exec rake assets:precompile is the exact rake task)

由于预编译仅在生产模式下完成,无需显式指定环境。

更新:

尝试将以下行添加到您的 Gemfile:

group :assets do
  gem 'therubyracer'
  gem 'sass-rails', "  ~> 3.1.0"
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
end

然后运行捆绑安装。

希望它会工作:)


推荐阅读