#= require not working after upgrade to Rails 5

455 Views Asked by At

I upgraded Rails 4.2.10 application to Rails 5. Solved errors with bundling and some deprecations. I am able to start the Rails Application, but when I try to load the Application, it fails with error, Invalid CSS after "#": expected id name, was "= require in the css file

I tried using @import, but it fails for external files in vendor/assets. Nevertheless, I want to understand why it isnt working anymore. In my config, I have the file in config.assets.precompile +=

In my index.html.erb,

<%= stylesheet_link_tag 'users' %>

In users.scss,

#= require "dashboard/dx"

Note: I am using sass-rails in my Gemfile

The error that I get,

Sass::SyntaxError in Dashboard::Users#index
Invalid CSS after "#": expected id name, was "= require "dash..."
Extracted source (around line #1):

#= require "dashboard/dx"
2

There are 2 best solutions below

0
On

The problem with this line

 #= require "dashboard/dx" 

This syntax is not working with .scss file. Either You have to write like this

@import 'dashboard/dx'

Or rename the file with .css extension.

Note: You can also try to rename with .css.scss extension May be it works also sometimes.

0
On

Hey I think the error is throwing because in your typical .scss file you would have to use either an @import "dashboard/dx" and#= requiremight only work in.css`