graphiql-rails: AssetNotPrecompiled error with Sprockets 4.0
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
Asset `graphiql/rails/application.css` was not declared to be precompiled in production.
Declare links to your assets in `app/assets/config/manifest.js`.
//= link graphiql/rails/application.css
and restart your server
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 https://github.com/rails/sprockets/issues/542 or https://github.com/rails/sprockets/issues/415
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 24
- Comments: 27 (1 by maintainers)
Fixed by following the instructions in the error pages, creating and adding the following lines to
app/assets/config/manifest.js:This work for me rails 6.02, sprockets 4.0.0, graphiql-rails 1.7.0, ruby 2.6.3p62
run into a new error, when try to run
rails testthat is because I only use graphiql under development, so in test it just cannot load these files. I finally decide to refactor it under initializers/assets.rb
Good !
And with Rails6, we can use webpack to help us to get things to work, try it.
I only use Graphiql in
developmentenvironment, so I only put this line into myconfig/environments/development.rb:Note: don’t forget to restart the rails server after change of configuration.
Should we agree on a suggestion for newcomers (like me today)? Maybe expand the Note on API Mode section of the README.
Option 1
Create app/assets/config/manifest.js and figure out a fix for the errors in test reported above?
Option 2
Create an empty app/assets/config/manifest.js:
And create a config/initializers/assets.rb with:
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:
Sprockets::FileNotFound: couldn't find file 'graphiql/rails/application.css'I found this issue https://github.com/rmosolgo/graphiql-rails/issues/13 however we are not in api-only mode.Is there a fix for this if we’re only using graphiql as a dev dependency?
@glitteringkatie I had the same problem and solved it by conditionally including the files in
assets.rbThis way, we are using both the
manifest.jsas well as theassets.rbfor declaring assets to be included, which might not be ideal, but at least solved our problem 😉This is cleanest hotfix for this issue by far 👏
It would be lovely if the following could be added to
manifest.jsbut it does not appear to be valid:However, this isn’t really an issue with
graphql-rails, rather it is to do with howsproketsworks.This seems the best option so far works for me. Thanks @LiinNs & @Timmitry .
This work for me, too. rails 6.0.1, graphiql-rails 1.7.0 ruby 2.5.1
I solved this in my test env by moving the
graphiql-railsto the development/test group