sprockets-rails: Error: Asset 'application.css' was not declared to be precompiled in production

I’m getting the error:

ActionView::Template::Error (Asset 'application.css' was not declared to be precompiled in production.
Declare links to your assets in 'app/assets/config/manifest.js'.

  //= link application.css
and restart your server):

But I have my application.scss (NOT .css) in app/assets/stylesheets and my app/assets/config/manifest.js says:

//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .scss

I’m using:

  • sprockets 4.0.0
  • sprockets-rails 3.2.1
  • rails 6.0.2.1

Temporary solution: Downgrade the gem as follows:

gem 'sprockets-rails', '2.3.3'

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 26
  • Comments: 16

Commits related to this issue

Most upvoted comments

rake tmp:clear helped me.

Doing what the error told me worked. My app/assets/config/manifest.js now looks like this:

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

I too have application.scss and not application.css. I have the same versions, except rails is 6.0.2.2

Same problem, but with application.scss.erb.

Workaroud it with

gem 'sprockets-rails', '2.3.3'

I’ve also just had this same problem with the same versions, and the same temporary solution worked for me.

I’ve had this issue come up occasionally and worked around it by adding an empty newline to /app/assets/config/manifest.js loading a page, and then reverting the change.

rake tmp:clear helped me.

This helped me, thanks

Same problem for me. Sprockets updated it’s documentation to explain why this is happening and how to fix it. Essentially, you’ll need to add subdirectories in your app/assets/stylesheets. This solution is the only one that’s worked for me so far.

Any solution to this? - it is in my manifest.js but also seeing the same:

I’m using and this happens intermittently:

  • ruby 3.1.3p185
  • rails (7.0.4.2)
  • sprockets (4.2.0)
  • sprockets-rails (3.4.2)

Getting this error too. It’s weird, it’s intermittent and doesn’t happen all the time.

2023-02-07T18:37:29.802242+00:00 app[web.1]: Declare links to your assets in app/assets/config/manifest.js.
2023-02-07T18:37:29.802243+00:00 app[web.1]:
2023-02-07T18:37:29.802243+00:00 app[web.1]: //= link application.css
2023-02-07T18:37:29.802243+00:00 app[web.1]:
2023-02-07T18:37:29.802244+00:00 app[web.1]: and restart your server):

And already included that file in manifest.js file.

//= link application.sass

Any ideas why it would be intermittent?

I’m using:

  • Ruby 3.0.4
  • Rails 7.0.4
  • Sprockets 4.1.1
  • Sprockets-Rails 3.4.2

rake tmp:clear didn’t work for me downgrading to gem ‘sprockets-rails’, ‘2.3.3’ with bundle install worked for me

rake tmp:clear

Worked. This should be added to the original post as the solution since so many people have 👍’d it.

The recommendation to downgrade sprockets-rails should be avoided. A local problem that can be easily solved by flushing your Rails.root/tmp directory should not require making a commit and then unduly influencing every other environment, dev machine, CI system, etc.

I ran into this issue because I had a //= require in my application.js that didn’t exist.

/* app/assets/javascripts/application.js.erb */

//= require this-a-non-existent-asset

Removing it fixed the error for me.