rails / sprockets

Rack-based asset packaging system
MIT License
943 stars 788 forks source link

Sprockets 4 require directive from SCSS #647

Open brodock opened 4 years ago

brodock commented 4 years ago

Expected behavior

application.css.scss

//= random/file
//= another/random/file.css

should work as it did in previous versions

Actual behavior

In both cases, you will get an error like:

Sprockets::FileNotFound: couldn't find file 'random/file' with type 'text/scss'
Checked in these paths: 

System configuration

s-mage commented 4 years ago

same for coffeescript. Problem is here https://github.com/rails/sprockets/blob/master/lib/sprockets/directive_processor.rb#L215-L217

      def process_require_directive(path)
        @required << resolve(path, accept: @content_type, pipeline: :self)
      end

and here https://github.com/rails/sprockets/blob/master/lib/sprockets/resolve.rb#L149-L150

        parsed_accept = parse_accept_options(mime_type, accept)
        transformed_accepts = expand_transform_accepts(parsed_accept)

As I understood two things are wrong here

This issue is hanging for a month here so I'll try to make a PR that fixes this

ricardopacheco commented 4 years ago

Same problem here. Waiting PR.

s-mage commented 4 years ago

I'll try to make a PR that fixes this

The fix is not that easy as I expected, so I shelved it and eventually forgot. I'm sorry. Don't expect me to do anything before the new year.

ricardopacheco commented 4 years ago

I tested your PR on my project and it worked correctly. In this case, I'll rollback to the latest version 3.x

niborg commented 4 years ago

Any progress on this issue @s-mage ? I suspect this is blocking ability to upgrade Rails for a lot of people. Can you share the specifics of the problem you are running into with the current open PR?

s-mage commented 4 years ago

@niborg no, I didn't do anything. I was out of ideas, that's why I asked for help in the PR description. The problem is that my PR is dirty and it breaks a lot of tests. I call it dirty because it tries to use inverted_transformers to find the source file and IMO there should be a better way to do it.

UPD: Just in case, https://github.com/rails/sprockets/pull/653 here is the PR

Josufst commented 3 years ago

Sorry, but what is a PR?

MarkerDave commented 3 years ago

I'm having the similar problem with application.js.coffee in Rails 5.0 and sprocket 4.0.2 In application.js.coffee the require is already without any extension.

#require codemirror results in error couldn't find file 'codemirror' with type 'text/coffeescript' the file sprockets should look for is codemirror.js

changing the application.js.coffee extension to .js does not fix the problem because then its unable to load .coffee files...

edit: added a little bit more information

s-mage commented 3 years ago

@MarkerDave https://github.com/rails/sprockets/pull/653#issuecomment-828736037 changing require something.scss to require something helped me

Josufst commented 3 years ago

Well, i didn’t find a solition :-(

krind regards,

Joost van der Linden

Skickad från min iPhöne

On 14 Jun 2021, at 16:27, Dave @.***> wrote:

I'm having the same problem with Rails 5.0 and sprocket 4.0.2

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

niborg commented 2 years ago

Is anyone still having this issue? As of 4.0.2 the standard upgrade guide works for me, combined with @s-mage's comment above to omit extensions.

ikalashniuk commented 1 year ago

Facing this now. Trying to upgrade Rails from 4.2.0 to 4.2.8. Renaming .css to .scss in project directories and adding copies of gems .css as .scss helps.

Now it's time to find a solution for .js/.coffee.