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

Rails 5 app can't boot if webpack-dev-server config is present #1847

Closed
ntaylor89 opened this issue Dec 20, 2018 · 13 comments
Closed

Rails 5 app can't boot if webpack-dev-server config is present #1847

ntaylor89 opened this issue Dec 20, 2018 · 13 comments

Comments

@ntaylor89
Copy link

I'm currently working upgrading a Rails app to Rails 5.
The webpacker gem is already installed, and at version 3.5.5.
Binstubs have been regenerated and configs have been updated.
Current ruby version is 2.3.7
All the yarn packages succesfully install.

No matter what version of Rails 5 I upgrade to, running any rails command like rails s or rails db:migrate gives me the following error:

can't modify frozen Array
/Users/nate/.rvm/gems/ruby-2.3.7@acloud/gems/actionpack-5.1.0/lib/action_dispatch/middleware/stack.rb:75:in `insert'
/Users/nate/.rvm/gems/ruby-2.3.7@acloud/gems/actionpack-5.1.0/lib/action_dispatch/middleware/stack.rb:75:in `insert'
/Users/nate/.rvm/gems/ruby-2.3.7@acloud/gems/webpacker-3.5.5/lib/webpacker/railtie.rb:51:in `block in <class:Engine>'
/Users/nate/.rvm/gems/ruby-2.3.7@acloud/gems/railties-5.1.0/lib/rails/initializable.rb:30:in `instance_exec'
/Users/nate/.rvm/gems/ruby-2.3.7@acloud/gems/railties-5.1.0/lib/rails/initializable.rb:30:in `run'
/Users/nate/.rvm/gems/ruby-2.3.7@acloud/gems/railties-5.1.0/lib/rails/initializable.rb:59:in `blockin run_initializers'
/Users/nate/.rvm/gems/ruby-2.3.7@acloud/gems/railties-5.1.0/lib/rails/initializable.rb:58:in `run_initializers'
/Users/nate/.rvm/gems/ruby-2.3.7@acloud/gems/railties-5.1.0/lib/rails/application.rb:353:in `initialize!'
/Users/nate/Workspace/a10/acloud/config/environment.rb:5:in `<top (required)>'
/Users/nate/.rvm/gems/ruby-2.3.7@acloud/gems/activesupport-5.1.0/lib/active_support/dependencies.rb:292:in `require'
/Users/nate/.rvm/gems/ruby-2.3.7@acloud/gems/activesupport-5.1.0/lib/active_support/dependencies.rb:292:in `block in require'
/Users/nate/.rvm/gems/ruby-2.3.7@acloud/gems/activesupport-5.1.0/lib/active_support/dependencies.rb:258:in `load_dependency'
/Users/nate/.rvm/gems/ruby-2.3.7@acloud/gems/activesupport-5.1.0/lib/active_support/dependencies.rb:292:in `require'
/Users/nate/.rvm/gems/ruby-2.3.7@acloud/gems/railties-5.1.0/lib/rails/application.rb:329:in `require_environment!'
/Users/nate/.rvm/gems/ruby-2.3.7@acloud/gems/railties-5.1.0/lib/rails/application.rb:445:in `block in run_tasks_blocks'

Which I can get around if I set the development config of webpacker.yml to nil, which causes webpacker to not insert the middleware (making the dev server not work).

Past issues have pointed to other gems, I've seen previous issues point to rails-admin. So I removed rails admin completely. Same.

The middleware is frozen by the time the webpacker-dev-server gem tries to insert itself.

I've done some binding.pry in the insert method of the middleware stack to see what's being inserted and when. the only middleware that currently seems to be inserted in a way that would trigger that method are ActiveRecord::Migration::CheckPending and the CacheStrategy middleware.

At this point I've removed everything I thought could be a culprit. Here's a current list of middleware at the time the dev-server attempts to insert itself

[Rack::Sendfile,
 ActionDispatch::Static,
 ActionDispatch::Executor,
=> [Rack::Sendfile,
 ActionDispatch::Static,
 ActionDispatch::Executor,
 ActionDispatch::Executor,
 ActionDispatch::Executor,
 ActiveSupport::Cache::Strategy::LocalCache::Middleware,
 Rack::Runtime,
 Rack::MethodOverride,
 ActionDispatch::RequestId,
 ActionDispatch::RemoteIp,
 Rails::Rack::Logger,
 ActionDispatch::ShowExceptions,
 ActionDispatch::DebugExceptions,
 ActionDispatch::Reloader,
 ActionDispatch::Callbacks,
 ActiveRecord::Migration::CheckPending,
 ActionDispatch::Cookies,
 ActionDispatch::Session::CookieStore,
 ActionDispatch::Flash,
 Rack::Head,
 Rack::ConditionalGet,
 Rack::ETag,
 Warden::Manager]

Any ideas? I'm at a loss at this point.

@ntaylor89
Copy link
Author

Also relevant: If I try to do a rails assets:precompile, it doesn't appear to be generating an application.css? Even though it was before?

My webpacker.yml file is pretty straightforward:

default: &default
  source_path: app/javascript
  source_entry_path: packs
  public_output_path: packs
  cache_path: tmp/cache/webpacker

  # Additional paths webpack should lookup modules
  # ['app/assets', 'engine/foo/app/assets']
  resolved_paths: []

  # Reload manifest.json on all requests so we reload latest compiled packs
  cache_manifest: false

  extensions:

    - .js
    - .sass
    - .scss
    - .css
    - .module.sass
    - .module.scss
    - .module.css
    - .png
    - .svg
    - .gif
    - .jpeg
    - .jpg

development:
  <<: *default
  compile: true
  # dev_server:
  # Reference: https://webpack.js.org/configuration/dev-server/
  dev_server:
    https: false
    host: localhost
    port: 3035
    public: localhost:3035
    hmr: false
    # Inline should be set to true if using HMR
    inline: true
    overlay: true
    compress: true
    disable_host_check: true
    use_local_ip: false
    quiet: false
    headers:
      'Access-Control-Allow-Origin': '*'
    watch_options:
      ignored: /node_modules/

test:
  <<: *default
  compile: true

  # Compile test packs to a separate directory
  public_output_path: packs-test

production:
  <<: *default

  # Production depends on precompilation of packs prior to booting for performance.
  compile: false

  # Cache manifest.json for performance
  cache_manifest: true

The following was in app/javascript/packs/application.js, but I've also commented it out (so nothing is there)

// var componentRequireContext = require.context("components", true)
// var ReactRailsUJS = require("react_ujs")
// ReactRailsUJS.useContext(componentRequireContext)

@gauravtiwari
Copy link
Member

@ntaylor89 Any chance both are related? #1700

@ntaylor89
Copy link
Author

ntaylor89 commented Dec 20, 2018

I don't think it is.

Eager load is set to false in development. We did have the rails_admin gem installed, but I removed it prior to the rails 5 upgrade.

@ntaylor89
Copy link
Author

It's definitely the same error, but the steps to fix didn't work for me.

@gauravtiwari
Copy link
Member

Might be another gem? thoughtbot/factory_bot_rails#247 same issue filed here: rails/rails#33745

Are you using spring?

@gauravtiwari
Copy link
Member

@ntaylor89 What happens if you run rails c?

@ntaylor89
Copy link
Author

ntaylor89 commented Dec 20, 2018

rails c gives the exact same bomb. Can't get to console because of it.

I did upgrade from factory_girl to factory_bot, however it's one of the gems I've disabled in the course of my troubleshooting.

@ntaylor89
Copy link
Author

We're not using spring, either 😞

@gauravtiwari
Copy link
Member

Ahh right, this is annoying (sorry)

I guess the best way would be to keep disabling gems and see which one fixes it. I guess a good starting point would be to disable anything that's not Rails and inserts a middleware. Are you using devise? I see warden middleware. I know you might have done this already, just suggesting :)

@ntaylor89
Copy link
Author

Actually, devise is maybe the one gem I haven't disabled that inserts middleware. Good catch.

I was going off of obvious names in the middleware, and since those register as rack My eyes just skipeed over them.

Thanks. I'll give throwing out devise a shot and get back to you. Past that, based on what's in my middleware, I might be running out of gems to disable.

@ntaylor89
Copy link
Author

Think I got it.

We have a rails engine included in our app as a gem, which I was able to isolate the problem to. And I fixed it by doing the the same thing rails_admin did in their gem:

Change this

 `initializer 'thing', after: :something_else do ...

To this

config.after_initialize do ..

We can close this. Thanks.

@guillaumebriday
Copy link
Member

Can this issue be closed ?

@guillaumebriday
Copy link
Member

@ntaylor89

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