简体   繁体   English

Sprockets 和 rails-ujs:无法加载此类文件 — coffee_script

[英]Sprockets and rails-ujs: cannot load such file — coffee_script

I'm using Rails without coffee-rails and using Rails UJS (Ruby on Rails unobtrusive scripting adapter).我正在使用 Rails 而不使用 coffee-rails 并使用Rails UJS (Ruby on Rails 不显眼的脚本适配器)。 After upgraded to sprockets 4, got the following error:升级到链轮 4 后,出现以下错误:

LoadError (cannot load such file -- coffee_script):

rails (976224b4de70) activesupport/lib/active_support/dependencies.rb:324:in `require'
rails (976224b4de70) activesupport/lib/active_support/dependencies.rb:324:in `block in require'
rails (976224b4de70) activesupport/lib/active_support/dependencies.rb:291:in `load_dependency'
rails (976224b4de70) activesupport/lib/active_support/dependencies.rb:324:in `require'
sprockets (4.0.0) lib/sprockets/autoload/coffee_script.rb:2:in `<top (required)>'

It's because Rails UJS is written in Coffee Script ( https://github.com/rails/rails/tree/785427b88c01654a441b8a7ed602feb35358285b/actionview/app/assets/javascripts ), so you'll need to use coffee-rails gem with sprockets.这是因为 Rails UJS 是用 Coffee Script 编写的( https://github.com/rails/rails/tree/785427b88c01654a441b8a7ed602feb35358285b/actionview/app/assets/javascripts ),所以你需要使用带有链轮的coffee-rails gem。

If you cannot use coffee-rails, migrate to webpacker then如果你不能使用coffee-rails,那么迁移到webpacker

import Rails from "rails-ujs"
Rails.start()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM