Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File to import not found or unreadable: variables on Rails 3.2.16 #523

Closed
seantanly opened this issue Feb 4, 2014 · 19 comments
Closed

File to import not found or unreadable: variables on Rails 3.2.16 #523

seantanly opened this issue Feb 4, 2014 · 19 comments
Labels

Comments

@seantanly
Copy link

After upgrading to version bootstrap-sass 3.1.0.1, I'm having the above error when precompiling assets.

My stylesheet contains.

@import "bootstrap";

After digging around a bit, i noticed the file

vendor/assets/stylesheets/bootstrap/bootstrap.scss 

is different from the previous working version 3.0.3.0, in which the @import statements are missing "bootstrap/" path component.

version 3.0.3.0

@import "bootstrap/variables"; 

version 3.1.0.1

@import "variables";

Adding the missing path component allows me to precompile successfully.

@glebm
Copy link
Member

glebm commented Feb 4, 2014

This should still resolve correctly. Can you post your Gemfile? Looks like you might be missing sass-rails or be locked to a very old version of one of the gems.

@seantanly
Copy link
Author

I'm running Rails version 3.2.16

My Gemfile reads

gem 'sass-rails',   '~> 3.2.3'

and Gemfile.lock

sass (3.2.14)
sass-rails (3.2.6)
  railties (~> 3.2.0)
  sass (>= 3.1.10)
  tilt (~> 1.3)

Thanks for looking into this.

@glebm
Copy link
Member

glebm commented Feb 4, 2014

The versions look fine, so something else must be wrong (other gems like sprockets-rails? config?). See @nex3's comment on @import behaviour.

@seantanly
Copy link
Author

I'm able to replicate the problem on a fresh installation of rails 3.2.16 with only bootstrap-sass as the additional gem.

The problem appears when the @import is called in a file which is not placed in the root folder of stylesheets.

e.g.

app/assets/stylesheets/dialog/signup.css.scss

inside signup.css.scss, simply

@import "bootstrap";

and precompiling will result in the above error.

Some additional setup

application.rb

config.assets.initialize_on_precompile = false

production.rb

config.assets.precompile += %w( dialog/signup.css )

@glebm
Copy link
Member

glebm commented Feb 4, 2014

Try setting it to true:

config.assets.initialize_on_precompile = true

@seantanly
Copy link
Author

config.assets.initialize_on_precompile = true

Tried it, still getting the same error.

@glebm
Copy link
Member

glebm commented Feb 4, 2014

I'm able to replicate the problem on a fresh installation of rails 3.2.16 with only bootstrap-sass as the additional gem.

Please push this to github

@seantanly
Copy link
Author

ok, here's the link.

https://github.com/seantan/ab

@glebm
Copy link
Member

glebm commented Feb 4, 2014

Please do not use require directives within Sass files as it messes with Sass path resolution. Just let @import handle it.

See https://github.com/glebm/ab/commit/482c141a8a0ae1c9fc95c1445095b0ecd9021149, and also rename the file to application.css.sass

@glebm glebm closed this as completed Feb 4, 2014
@seantanly
Copy link
Author

My bad for a typo in the production.rb. Fixed it, please take a look again.

https://github.com/seantan/ab/commit/29034aa34550782c790baf4630c444afe156cf7c

The problem occurs when bootstrap is imported from a file that is "non-root" level relative to assets/stylesheets.

@glebm glebm reopened this Feb 4, 2014
@glebm glebm mentioned this issue Feb 4, 2014
@glebm
Copy link
Member

glebm commented Feb 4, 2014

Try the following gem versions (backports to Rails 3):

gem 'sprockets-rails', '=2.0.0.backport1'
gem 'sprockets', '= 2.2.2.backport2'

Seems to work with the sample app. Updated docs 0f37b4d

@glebm
Copy link
Member

glebm commented Feb 4, 2014

Nvm, doesn't work. Btw, unrelated but it's better to set precompile in application.rb rather than production.rb so you can run precompile in other environments.

@glebm
Copy link
Member

glebm commented Feb 5, 2014

At last, a workaround with backports of Rails 4 pipeline fixes:

gem 'sprockets-rails', '~> 2.0.0.backport1'
gem 'sprockets', '~> 2.2.2.backport2'
gem 'sass-rails', github: 'guilleiguaran/sass-rails', branch: 'backport'

As a bonus you get Rails 4 speed deployments .

@seantanly
Copy link
Author

Thanks for working on this tirelessly! I'll try out the workaround soon.

Btw, any reason why there was a @import path change in the bootstrap/bootstrap.scss moving bootstrap-sass up to version 3.1.0.1 ? Naively, it seems to be only thing stopping the gem from working correctly in this situation. Is it possible/correct to revert the change?

Since bootstrap-sass has become the Official port of Bootstrap to Sass , 👍
Rails apps that still runs on Rails 3.2 (without the updated sprockets/-rails) will run into this problem when switching over from other bootstrap ports.

IMO, it is important that the gem works out of the box without the workaround as it introduces uncertainties (backport gems and branch) which potential users might not accommodate.

Thanks again @glebm for for the incredibly fast response in coming up with the workaround solution. 👍

@glebm
Copy link
Member

glebm commented Feb 5, 2014

I changed @import to use paths relative to the file in order to avoid relying on modified Sass load path, since the file directory is always present in @import path. This is mainly for non-ruby users (e.g. node-sass), as ruby users always get the load path on require 'bootstrap-sass'.

This does work out of the box in Rails 4, but, unfortunately, there is a bug in the older versions of the gems that has only been fixed in the backports. Meanwhile, I've added a note on this to Readme.

@glebm
Copy link
Member

glebm commented Feb 6, 2014

Released 3.1.0.2 with the simpler fix above (does not require upgraded pipeline).

gem 'bootstrap-sass', '~> 3.1.0.2'

@seantanly
Copy link
Author

@glebm Tested the workaround and it works. Many thanks for the detailed explanation and releasing 3.1.0.2 which fixes the issue without requiring the workaround gems. 👍

@seantanly
Copy link
Author

Just want to update that 3.1.0.2 works for my Rails 3.2.16 App, even with gems still inside :assets group, and initialize_on_precompile = false.

@glebm glebm closed this as completed Feb 6, 2014
glebm added a commit that referenced this issue Apr 19, 2014
carols10cents added a commit to carols10cents/trusty-cms that referenced this issue Jun 15, 2014
On advice of
twbs/bootstrap-sass#523 (comment)

This seems to let both compass and partials be found!!!!
@bcackerman
Copy link

FYI this works in Rails 3.2

gem 'compass-rails', '1.1.7'
gem 'sass-rails', '3.2.6'
gem 'bootstrap-sass', '~> 3.1.1.0'

vinayvinay pushed a commit to alphagov/publisher that referenced this issue Sep 8, 2014
Publisher deploys are failing because during
assets precompilation, we're seeing an issue
similar to:

twbs/bootstrap-sass#523

This command fails during deploys:

govuk_setenv publisher bundle exec rake \
RAILS_ENV=production RAILS_GROUPS=assets \
assets:precompile

Rails 4 has removed the :assets group from
the generated Gemfile. As mentioned in the
above discussion, it seems OK for gems to
move in that direction and to suggest
removing :assets group:

rails/rails@49c4af4

We have heavy weights like therubyracer in
that group, which has been reported to be
memory intensive. hence i'm avoiding
removing :assets group entirely.

For the current issue, it is sufficient to move
sass-rails out of the :assets group to get assets
to precompile.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants