Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asset pipeline require not working with coffeescript [v1.4.2 and above] #415

Closed
tmikoss opened this issue Nov 27, 2015 · 5 comments
Closed

Comments

@tmikoss
Copy link

tmikoss commented Nov 27, 2015

Calling #= require ./other_file, in a .js.jsx.coffee file no longer seems to work in version 1.4.2 and above. The file is not evaluated - tested by putting a console.log at the top of the required file.

Changing the extension to .js.jsx and calling //= require ./other_file works as expected.

Last version of react-rails where it worked as expected was 1.3.3.

Setting config.react.jsx_transformer_class = React::JSX::JSXTransformer does not fix the issue.

@rmosolgo
Copy link
Member

Hmm if file extensions makes a difference, I bet it's related to

#385
#411

@tmikoss
Copy link
Author

tmikoss commented Nov 27, 2015

Glanced over the changes in those two, but there's nothing that stands out as problematic to me. However, I'm not an expert on how the asset pipeline works.

I've created a minimal app that reproduces the issue - https://github.com/tmikoss/react-rails-coffeescript-require-example

@rmosolgo
Copy link
Member

Man, it's been a weekend of Sprockets-wrangling.

Thanks the the demo project. I cloned it locally and started it up. Sure enough, I only got the three log statements. So I pointed it at my local react-rails and started poking and prodding.

Some things I noticed

It makes me think that somehow our transformer doesn't play well with the engine scheme.

Some things I tried

  • Added a test for #= require in js.jsx.coffee. It worked but that's because I'm testing with Sprockets 2.
  • Mostly, I tried tweaking stuff in engine.rb
    • Adding the .js.jsx.coffee extension to the CoffeeScript mime-type (didn't work, that was before I realized how different Sprockets 3 vs master was)
    • Registering the JSX engine along with the transformer (didn't work)
    • Registering the CoffeeScript processor as a transformer (didn't work)
    • Manually adding the Sprockets::DirectiveProcessor for .js.jsx.coffee (didn't work)

So far, nothin! But it has to be, has to be, has to be, something related to engines vs. transformers.

I've got to get a failing spec in the repo. I'm going to try making some gemfiles with sprockets 3 and Sprockets 2!

@rmosolgo
Copy link
Member

I opened an issue an issue on Sprockets to see if that team has any suggestions: rails/sprockets#231

@rmosolgo
Copy link
Member

Tried this again in hopes that it would have been fixed by some work in the last few months, and it seems like it was:

~/code/react-rails-coffeescript-require-example $ bundle update react-rails
# ...
# ... 
Using railties 4.2.5
Installing sprockets-rails 3.1.1 (was 2.3.3)
Using coffee-rails 4.1.0
Installing react-rails 1.8.0 (was 1.5.0)
Using rails 4.2.5
Bundle updated!

image

🎉

Since the previous update also bumped sprockets-rails, I locked sprockets-rails to ~> 2.0 and tried again:

~/code/react-rails-coffeescript-require-example $ bundle update sprockets-rails
# ... 
Using sprockets-rails 2.3.3 (was 3.1.1)
# ... 

image

🎊

@tmikoss , Are you able to update to the latest react-rails? OK to close this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants