DaniG2k
DaniG2k

Reputation: 4903

Rails: assets not precompiling on Capistrano deploy step due to missing variables

I am having some trouble pre-compiling assets for a new Rails 6 app I'm working on.

My application.scss looks like this:

@import 'vars';
@import 'bootstrap';
@import 'bootstrap_overrides';
@import 'font_awesome5.css';
@import 'base';
@import 'dashboard';
# etc...

but upon deploying to production with Capistrano, the asset pre-compilation step fails with the following:

SassC::SyntaxError: Error: Undefined variable: "$padding"
       on line 18:12 of app/assets/stylesheets/base.scss
>>   padding: $padding;

   -----------^

The $padding variable is defined in vars.scss:

$padding: 60px 0px;

and, as mentioned, is being imported in application.scss. Why would other files complain that it's necessary if application.scss is already importing it?

The app works fine in development.

Thanks in advance!

Upvotes: 4

Views: 573

Answers (1)

Dave Kruse
Dave Kruse

Reputation: 119

EDIT: The better answer was given by vmarquet in response to a similar question. https://stackoverflow.com/a/62238810/4493692

To sum up vmarquet's answer, the latest version of sprockets defaults to compiling all scss files in assets/stylesheets as top-level assets. What you want is to compile your application.scss file, not all partials and imports independently.

This is configured in manifest.js. Instead of the default directory includes, you will want something like this:

//= link_tree ../images
//= link application.css
//= link application.js

Upvotes: 2

Related Questions