-
Notifications
You must be signed in to change notification settings - Fork 137
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
AssetNotPrecompiled error with Sprockets 4.0 #75
Comments
I have the same problem with Rails 5.2.3, sprockets 4.0.0, graphiql-rails 1.7.0, ruby 2.6.5. As a short-term fix, downgrading sprockets to 3.7.2 worked for me. |
I have the same problem - found this: doorkeeper-gem/doorkeeper#834 Looks like the same issue in another project. Not sure if the same resolution will apply here. rails 5.2.3, sprockets 4.0.0, graphiql-rails 1.7.0, ruby 2.6.1p33 |
Fixed by following the instructions in the error pages, creating and adding the following lines to //= link graphiql/rails/application.css
//= link graphiql/rails/application.js |
I have the same issue and this solution worked great locally! However we're exposing the graphiql route on development only. So when a prod build ran, we got: Is there a fix for this if we're only using graphiql as a dev dependency? |
Same issue +1 |
@glitteringkatie I had the same problem and solved it by conditionally including the files in # config/initializers/assets.rb
Rails.application.config.assets.precompile += […] if Rails.env.development? This way, we are using both the |
Awesome, thanks @Timmitry! We'll try that next (but it's not an immediate issue for us so probably won't be able to report back on success for a bit) |
This work for me run into a new error, when try to run
that is because I only use graphiql under development, so in test it just cannot load these files. Rails.application.config.assets.precompile += %w( graphiql/rails/application.js graphiql/rails/application.css ) if Rails.env.development? Good ! And with Rails6, we can use webpack to help us to get things to work, try it. |
This work for me, too. |
Should we agree on a suggestion for newcomers (like me today)? Maybe expand the Note on API Mode section of the README. Option 1Create app/assets/config/manifest.js and figure out a fix for the errors in test reported above? //= link graphiql/rails/application.css
//= link graphiql/rails/application.js Option 2Create an empty app/assets/config/manifest.js: mkdir -p app/assets/config && touch app/assets/config/manifest.js And create a config/initializers/assets.rb with: # config/initializers/assets.rb
if Rails.env.development?
Rails.application.config.assets.precompile += %w[graphiql/rails/application.js graphiql/rails/application.css]
end |
This doesn't seem to work for me. I just fired up a new rails app, skipping sprockets during install but deciding to add it on later. I have |
@chadwilken it's manifest.js, how it didn't work? Did you try option 1 or 2 above? I thought I had a sample repo, but I haven't uploaded it yet. I'll share it when I get to work tomorrow. |
Sorry, that was a typo on my end. It is manifest.js. I tried both and they didn't work. I suspect that it is because I skipped sprockets and something is not configured correctly. If you have a working Rails 6 repo that would be awesome. |
The repo I had in mind is a little more complicated, so I pushed a demo repo (leonelgalan/rails-api-graphiql-demo), with the relevant steps as a single commit:
After that I can go to http://localhost:3000/graphiql and run query {
testField
} And get this back: {
"data": {
"testField": "Hello World!"
}
} |
- Fix manifest per: rmosolgo/graphiql-rails#75 - Nest graphql_controller in Api module - Clean up routes
I solved this in my test env by moving the |
Adding precompile assets in config/initializers/assets.rb is not a very good approach, because from Sprockets 4 we should add all dependencies in the manifest.js. I fix it in another way (by code), also not ideal, but at least I can decide which env I allow for the graphiql queries. The graphql view will be still visible, but it will always respond with an Unauthorizer error. # config/routes.rb
# mount the engine for all environments
mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/graphql" # app/controllers/graphql_controller.rb
class GraphqlController < ActionController::API
before_action :authorize_environment
# ... the controller code ...
private
def authorize_environment
unless Rails.env.development?
render json: { error: { message: "401 Unauthorized" }, status: 401 }
end
end In the case you don't want to show the GraphiQL view, you can overwrite the controller of the engine following the Edge Rails guides. But I don't recommend this approach, because your overwritting will create a dependency with the gem and you will risk to have to make adjustments in every new version of the gem if they change the code you are overwritting. |
FWIW Sprockets 4.0.0 seems to require all the files required by My Either you change your app or adapt the gem, but they must be have same type/extension. |
I only use Graphiql in config.assets.precompile += ['graphiql/rails/application.js', 'graphiql/rails/application.css'] Note: don't forget to restart the rails server after change of configuration. |
It would be lovely if the following could be added to if (process.env.NODE_ENV === 'development') {
//= link graphiql/rails/application.css
//= link graphiql/rails/application.js
} However, this isn't really an issue with |
Hello everyone. Please I have a problem with my code. I am building a micro-reddit app and this is the code I have in my application.html.erb <title>Raddit</title> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %><%= likn_to "Raddit", root_path %>
<% if user_signed_in? -%>
<% flash.each do |name, msg| %>
<%= content_tag(:div, msg, class: "alert alert-info") %>
<% end %>
But when I am running the rails server I am getting this error:
Sprockets::Rails::Helper::AssetNotPrecompiled in Links#index
And it is emphasizing on this line which is the cause of the error:
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
Can you guys help me solve this issue?
<%= yield %>
|
This is cleanest hotfix for this issue by far 👏 |
I see this error on Rails 6.1.3 / Ruby 2.7.2p137 too 😢 I've tried both the 'manifest.js' fix and the 'development.rb' fix – sadly neither does the trick! I get
in my log - and I wonder what adds the '.debug' suffix to the files? I try
which I believe to be fairly correct - but as you see: no .debug attached to the two graphiql resources!?? Sprockets: 4.0.2 |
@jscho13 on rails/sprockets-rails#376 (comment) mentioned that the issue is solvable by imitating production.rb - which I did, and bingo, all is well 😄 |
Didn't worked for me for the same problem. |
I recently used it with success in a couple of my new projects. |
For us using Rails 5.2.6 api only we just added a guard statement in the The reason why we did this is because we aren't using sprockets at all for this project in production, except for in development, and it's not a perfect fix but it at least keeps sprockets from running on our production deployment on heroku and getting this error from sprockets. |
Problem:
When running graphiql-rails and sprockets 4.0.0, accessing graphiql raises
Sprockets::Rails::Helper::AssetNotPrecompiled in GraphiQL::Rails::Editors#show
Following the suggestion of
Doesn't seem to fix anything
I've reproduced the exception with a fresh rails app here: https://github.com/wesleyjellis/sprockets_graphql (Rails 6.0.0, sprockets 4.0.0, graphiql 1.7.0, ruby 2.6.3)
It's possible this is related to rails/sprockets#542 or rails/sprockets#415
The text was updated successfully, but these errors were encountered: