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

Cannot use require directive from registered transforms/preprocessors. #156

Closed
matthewlehner opened this issue Nov 11, 2015 · 14 comments
Closed

Comments

@matthewlehner
Copy link

This is coming from my experience with sprockets-es6, which is using the recommended preprocessor/transform syntax rather than registering as an engine.

Calling //=require somefile will result in:

Sprockets::FileNotFound: couldn't find file 'es5_file' with type 'text/ecmascript-6'

sprockets-es6 is registered like this:

register_mime_type 'text/ecmascript-6', extensions: ['.es6'], charset: :unicode
register_transformer 'text/ecmascript-6', 'application/javascript', ES6
register_preprocessor 'text/ecmascript-6', DirectiveProcessor
register_engine '.es6', ES6

but changing to simple an engine fixes the behaviour:

register_engine '.es6', ES6, mime_type: 'application/javascript'

I've opened another issue at TannerRogalsky/sprockets-es6#19, but it feels like this is an issue in the 3.x branch of Sprockets.

@rafaelfranca
Copy link
Member

This is actually an issue with sprockets-rails. I had this same issue yesterday. The reason is, you es5_file.es6 file is in the Rails.assets.precompile list while it should be es5_file.js there. Could you try with sprockets-rails master?

@rafaelfranca
Copy link
Member

oops, I mean same_file.es6 that should be some_file.js in the Rails.assets.precompile list.

@rafaelfranca
Copy link
Member

You can see the test that I wrote yesterday to make sure this works here 3a7a5fe

@matthewlehner
Copy link
Author

Thanks! This does look right, and from the Rails perspective the issue is only happening for me during the rake assets:precompile process.

That said, I've reproduced it with some similar tests in the sprockets-es6 repo, however, these are running against sprockets 3.4.0. I'll check if these tests pass on the 3.x branch as it looks like the way that the built in processors are registered have changed from engines to transforms/preprocessors on master.

I'll do a bit more sleuthing!

@rafaelfranca
Copy link
Member

It is an issue in the way sprockets-rails works that is fixed in its master version so I'm closing this one. Thanks

@matthewlehner
Copy link
Author

@rafaelfranca I'd like to re-open this long-dead issue (is this okay?) I can open a new issue if that's preferable.
I've recently had some more time to dig in here and am getting the same error in a vanilla Rails app with the following gems:

gem 'sprockets', '~> 4.0.0.beta2'
gem 'sprockets-rails', github: 'rails/sprockets-rails'
gem 'babel-transpiler', '~> 0.7.0'

To reproduce, clone https://github.com/matthewlehner/sprockets-es6-mime-failures

I've tried to keep this as minimal as possible, and have only added the required gems to compile es6 and renamed the JavaScript entry point to app/assets/javscripts/application.es6.

@rafaelfranca rafaelfranca reopened this Mar 29, 2016
@rafaelfranca
Copy link
Member

It is fine. I'll take a look.

@schneems
Copy link
Member

schneems commented Apr 6, 2016

Any luck?

@michaelherold
Copy link
Contributor

I went through @matthewlehner's example app. It fails to find jquery through the application.es6 file on Sprockets 4.0.0.beta2.

However, when you use sprockets master, it correctly finds the issue.

I did a bisect and discovered that the behavior was fixed with the changes from #255. Specifically, if I cherry-pick 4da2114 onto the v4.0.0.beta2 tag the example application works as expected.

@matthewlehner could you give that a try (or just try master) to see if it works for you as well?

@matthewlehner
Copy link
Author

@michaelherold I think you're right! I tried this again yesterday in a different app and couldn't reproduce it, but still was still broken in the example app regardless of the version of Sprockets I was using – it might have been a caching issue though, as I've noticed that the cached assets are not busted when options for the compiler are changed.
I'll give it a shot with Sprockets master and see what I can find.

@lifeiscontent
Copy link

@matthewd @schneems @rafaelfranca any updates on this? Is this working as expected? I seem to be having the same issue, but inside of a middleman app using sprockets.

@matthewlehner
Copy link
Author

Just tested this morning. Still experiencing this in Rails 5 with Sprockets 4 beta.2, however, it seems to be fixed on master.

Perhaps another beta version could be released to get this working?

@schneems
Copy link
Member

I released master with a few other fixes for 4.0.0.beta3. Give it a whirl. Let me know if the issue comes back.

@matthewlehner
Copy link
Author

@schneems Thanks so much! 😻

Just watched your RailsConf talk about inheriting Sprockets and loved it. Thanks for the work on the 4.0 release so far!

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

5 participants