Less.js LoadError - no such file to load — less on

2019-06-19 00:09发布

I am trying to test out less.js on a new project. I am 100% sure the javascript file is loading fine but I keep getting this error on the less file that is in my css folder. I am going to compile it using the less.app before I launch but I would rather just let less.js do it during development. Is there a problem with it not letting the browser access the file since it is .less or something else? Thanks (running ubuntu 11.04 and ruby v1.9.2, same error in firefox and chrome)

Here is my head.haml file where I link to less.js & app.less (which are both in the correct folders)

%link{:rel => "stylesheet/less", :type=>"text/css", :href => "/assets/css/app.less"}
%script{:src => "/assets/js/less-1.1.3.min.js", :type => "text/javascript"}

Here is the error I get in the browser when I open up app.less

LoadError at /assets/css/app.less
no such file to load -- less (in /home/blake/biddrr/assets/css/app.less)

Ruby    /home/blake/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb: in require, line 239
Web GET localhost/assets/css/app.less

标签: css ruby less
4条回答
可以哭但决不认输i
2楼-- · 2019-06-19 01:03

I had the same problem and I did some digging. The no such file to load -- file error means that Rails can't find the file, in our case less, in the system.

This can be easily solved by going in the Gemfile and adding

group :assets do
  gem 'less'
end

After that run a bundle install to get the less gem.

Finally restart your rails server rails s

I am kinda new to RoR and Ruby so may be some of the things I've done are useless or there are smarter solutions. Anyway this solved my problem :) I hope will work for you too!

查看更多
地球回转人心会变
3楼-- · 2019-06-19 01:06

Just put gem 'less' into assets section in your gemfile. And restart your server.

查看更多
Rolldiameter
4楼-- · 2019-06-19 01:09

Look on your web server terminal. I'm using WEBrick and got "ActionView::Template::Error (no such file to load -- less" after going through this http://railscasts.com/episodes/328-twitter-bootstrap-basics?view=asciicast screencast. All I did to fix it was reset the web-server.

查看更多
贼婆χ
5楼-- · 2019-06-19 01:13

You may need to assign a .less mime type on your web server to ensure it knows what to do with this file.

查看更多
登录 后发表回答