Rails 6 sprockets error, cannot find source.coffee file
Asked Answered
M

4

7

Upgrading from rails 5.2 to rails 6.0.1, I get the following error when loading a page in development mode:

Sprockets::FileNotFound - couldn't find file 'leaders.source.coffee'
Checked in these paths: 
  app/assets/audios
  app/assets/config
  app/assets/images
 ...

My app/javascripts directory does not have any filed called leaders.source.coffee or any file starting with leaders. I have searched my code base and I could not find any reference to leaders.

My manifest file is

#app/assets/config/manifest.js is
//= link_tree ../images
//= link_tree ../audios
//= link application.css
//= link application.js
//= link print.css

How do I fix this?

Misfit answered 14/12, 2019 at 19:24 Comment(0)
M
7

I am not sure why, but setting debug to false fixed this, i.e.

config/environments/development.rb

config.assets.debug = false

If this does not work, or you cannot permanently use this setting, you might like to try @Guillaume Petit's answer below.

Misfit answered 15/12, 2019 at 21:21 Comment(2)
This worked for me as well. I found the same issue after upgrading Rails 5.2.3 to 5.2.4. It seems that the issue was caused by Sprockets being upgraded to version 4.Stylographic
I encountered the same, anyone knows what a more permanent fix to this would be, besides changing this setting - which I cannot do permanently?Hughs
J
5

Removing the cache folder did the trick for me

rm -rf tmp/cache
Josefinejoseito answered 20/4, 2021 at 20:40 Comment(2)
Interesting, this worked for me. I am considering making this the accepted answer, do you have an explanation for why it works? I also like that your answer fits your the credo on your SO profile (when in doubts, I delete).Misfit
Haha, yes indeed. I did not dig into sprokets source code, so take that as "most likely". I guess that in order to speed up dev auto rebuild, sprokets must be caching some stuff in that tmp folder, so removing just bust it and let it rebuild everything from scratchJosefinejoseito
A
2

My problem was require_tree . was pulling in a coffeescript file in a subdirectory. If the file is present, I get an error message it cannot find it in the root directory. The file is empty with no code, just comments so I deleted it but then I get an error message that it cannot find it when looking in the subdirectory.

I solved this by downversioning from sprockets 4.0.2 to `3.7.2'.

gem 'sprockets', '3.7.2'
Averir answered 16/2, 2021 at 14:40 Comment(0)
P
1

I get the same error if I call rails generate controller [controllername] from the command line, but not if I manually make a controller. I'm guessing there's some sort of version conflict in what's generating the files, and what's running the files. It's not much more work to just manually make the things, so I'm just using that as a workaround.

The solution was to go into app/assets/javascripts/ and delete the coffee file generated there. Our guess is that the boilerplate code we're working off of (we're students) is the source of the problem.

Placido answered 21/11, 2020 at 18:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.