rails 5.1.0.rc1, sass-rails 5.0.6: variables declared in one file undefined in second file #474
Comments
From @stepheneb on April 3, 2017 20:17 Example repo with simple Rails 5.1.rc1 app. At this commit referencing the sass var from At next commit referencing sass variable from second imported file doesn't work: At last commit using sass-rails v5.0.6 instead of master branch version of gem (Rails 5.1.rc1 generated github reference for sass-rails gem in Gemfile) problem with second @import still present: |
From @RemyMaucourt on April 21, 2017 13:29 I have the exact same problem with sass-rails 6.0.0.beta1. |
I don't remember in any change in the Rails framework or sass-rails that could cause this. What is the behavior in sass command line? |
Just confirmed that the sass behavior is what you are expecting. |
I tried to find when this changed and I could not find a combination of version where this used to work. Do you know if it ever worked? |
From @stepheneb on April 21, 2017 16:47 @rafaelfranca can you describe more how you tested for the correct behavior? I tested with new Rails 5.1.rc1 app in this simple repo with only 7 commits: https://github.com/stepheneb/sass-demo I was not able to reference sass variables in other files. I have a much larger app running in Rails 5.0.2 where the referencing of sass variables works fine. If it would be helpful I can add a branch to my simple sass-demo repo which uses Rails 5.0.2. I expect to see the referencing of sass variables in other files work (just like it does in my larger project) -- but with confusing bugs like this maybe it won't work ... and that will provide a useful clue. |
I tried both Rails 5.0.2 and 5.1. With both sass-rails 5.0.x and 6.x and sprockets 3 an I could not get that working. If you could make the sass-demo repo working that would be great so we could narrow down what changed. |
From @stepheneb on April 21, 2017 18:7 I just created this new repo using Rails 5.0.2 and the sass variable defined in |
From @stepheneb on April 21, 2017 18:19 Am getting a bit confused ... Here is the same set of commits in a new repo -- just using Rails 5.1.0.rc2. -- and the sass variable defined in Now I need to find out why my earlier test with Rails 5.1.0.rc1 didn't work (at this point I'm not convinced it has to do with Rails 5.1.0.rc1). |
From @stepheneb on April 21, 2017 19:59 The problem is with At the time I created the original sass-demo repo with Rails 5.1.0.rc1 This seems strange because in the same The demo built with Rails 5.1.0.rc2 instead resolves to https://github.com/stepheneb/sass-demo-5.1.0.rc2/blob/master/Gemfile.lock#L141 In the original sass-demo repository locking the Sprockets dependency in the Gemfile to 3.7.1 fixes the problem. |
I see. So this is an issue with sprockets. |
So a solution could be to force sprockets version to 3? |
FWIW, for me, the problem exists in sass-rails 5.0.2 but works fine when i downgrade to sass-rails 4.0.5. |
We are experiencing the same problem using rails 5.0.6, sprockets 3.7.1 and sprockets-rails 3.2.1 Any updates on this? |
@rafaelfranca any idea what changed? There's lots of links on this thread. Which one is the example app that works with sprockets 3 but not with sprockets 4? |
@schneems here's a fresh Rails 5.1 repro app w/ a Just run Works with sprockets 3.7.1; fails with sprockets 4.0.0.beta6 |
So, what's the resolution on this one? Downgrade sprockets? Anyone working on a fix? |
Not sure how much this helps, but a workaround that appears to work is to update the manifest to directly link the files you'd like pre-compiled:
Working example from the previously failing 'bad' branch example posted earlier:
|
My app was on Rails 4.2, Sprockets 2.12, and Sprockets-rails 2.3 and did not encounter this error. I started getting this error once I upgraded my app to Rails 5.1; Sprockets 3.7, and Sprockets-rails 3.2. I tried bumping Sprockets down to 3.3 but still seeing the error. |
remove "= require_self" and "=require_tree ." from application.scss and it should work |
Thank you @samanthi22. Your suggestion worked for me. |
Thanks!!!! @samanthi22 need to get this solution into a more SEO friendly format |
We have an rails 4.2 app with sprockets 3.7.2 and facing the same problems. Our main file does not have the above statements. It just includes several import-statements like
Still getting errors like
|
Have done this, and I'm still getting the pesky error. Any further advances as to the cause/resolve? Here's my config:
|
have same issue on sprockets (3.7.2) and rails 5.0.7.2. Removing require_self and require_tree didn't help. Uptate: in my case it's working with explicitly set gem 'sprockets-rails', '2.3.3' in Gemfile |
@jwcooper thank you, that also fixed the issue for me. For anyone else having this issue with Rails, I'd recommend reading the manifest section of the UPGRADING.md file https://github.com/rails/sprockets/blob/master/UPGRADING.md as it gives a very good description of the situation. @jrochkind thank you for contributing that---it probably saved me hours of my life. |
So glad it helped, took me a while to figure out what was going on when I was confused too, and then write it up -- thanks for saying so @scpike ! |
I can also confirm that @jwcooper solution of updating the
I use a separate file to create SCSS variables and then reference them in later files based on the import order in my I'm running:
Note that this was working fine on my local development machine and I only encountered the issue when I deployed and my CI ran the |
Just ran into this issue yesterday and and had a hard time figuring out this behaviour. Just after I switched everything to webpacker and got weird 500 errors without a stacktrace I investigated some more and stumbled over the The solution is to replace |
I am using Rails v6.0.3.4 and getting this error during the production build. I have found a solution using which I am able to resolve the issue. Before going to the solution, let me tell you the function of "link_directory" of Sprockets. "link_directory" use the pre-processor based on the file extension of the given path. In "manifest.js" the "link_directory" applied on "../stylesheets" file. So, will use sass pre-processor for "application.scss" and all other .scss files. Also, files in subdirectories will not be linked. I think the order of applying pre-processor on those files under the "stylesheets" directory important. So, what I did, I simply modified the file structure under that directory, like below app/assets/stylesheets The content of the application.scss is like below
After doing the above changes, then my build got successful. |
@f-mer thanks! |
From @stepheneb on April 3, 2017 17:13
In a very simple rails 5.0.1.rc1 application a sass variable defined in the file
colors.scss
is available inapplication.scss
(the file that importscolors.scss
) but not in a second file,welcome.scss
imported byapplication.scss
.file:
colors.scss
file:
application.scss
This works correctly.
However if I remove the p styling from
application.scss
and instead reference it from a second filewelcome.scss
Rails generates anUndefined variable: "$backgroundcolor".
error when rendering.file:
application.scss
file:
welcome.scss
Earlier I described this bug in a rails issue: rails/rails#28628 however I think the bug might be in the sass-rails gem.
Copied from original issue: rails/sass-rails#396
The text was updated successfully, but these errors were encountered: