【发布时间】:2021-03-13 11:10:12
【问题描述】:
我有一个 ROR 应用程序,我使用 yarn 安装了 toaster 和 jQuery:yarn add jquery ; yarn add toastr。还将它们的配置添加到 application.js:
// app/assets/application.js
//= require jquery
//= require rails-ujs
//= require activestorage
//= require turbolinks
//= require toastr/toastr
同时更新 application.scss:
app/assets/stylesheets/application.scss
@import "toastr/toastr";
应用在本地测试并且运行良好。但是当我尝试将它推送到 Heroku 时,我收到了这个错误:
remote: Running: rake assets:precompile
remote: Yarn executable was not detected in the system.
remote: Download Yarn at https://yarnpkg.com/en/docs/install
remote: I, [2020-12-01T12:43:31.158434 #1643] INFO -- : Writing /tmp/build_7363272e/public/assets/application-2b2ad3277391444ddcebbd59536eb9b2f05b9a3ad61300e3ed828b7533f992fb.js
remote: I, [2020-12-01T12:43:31.159231 #1643] INFO -- : Writing /tmp/build_7363272e/public/assets/application-2b2ad3277391444ddcebbd59536eb9b2f05b9a3ad61300e3ed828b7533f992fb.js.gz
remote: rake aborted!
remote: SassC::SyntaxError: Error: File to import not found or unreadable: toastr/toastr.
remote: on line 2:1 of app/assets/stylesheets/application.scss
remote: >> @import "toastr/toastr";
...
remote: !
remote: ! Precompiling assets failed.
remote: !
我需要做什么来解决这个问题?
【问题讨论】:
-
最好的方法是在heroku中使用elements.heroku.com/buildpacks/yarnpkg/yarn这个纱线构建包,并在推送到heroku之前预编译所有资产,如果这不适合你,请继续使用这个gem github.com/tylergannon/toastr-rails
-
@adityapandit17 谢谢,我想过但还没试过
-
heroku buildpacks:add --index 1 heroku/nodejs解决了我的问题,因为纱线我需要在这里使用“多个 Buildpacks”更多信息:devcenter.heroku.com/articles/… -
是的,roman,很高兴我的回答对您有所帮助。
标签: ruby-on-rails heroku yarnpkg