Skip to content

"can't modify frozen Array" error in Rails 5 #385

Closed
@wjordan

Description

@wjordan

Error is raised whenever require 'sass/plugin/rack' is included anywhere in a Rails 5 application.
Minimal repro bash script (just adds require 'sass/plugin/rack' in an initializer and starts a new rails server):

#!/bin/bash

# Run in a temp dir and clean up after
TEST_DIR=$(mktemp -d)
pushd ${TEST_DIR} > /dev/null
trap "rm -rf ${TEST_DIR}; popd > /dev/null" EXIT

# Generate new Rails project (override version with RAILS_VERSION)
: ${RAILS_VERSION:=5.0.0.1}
rails _${RAILS_VERSION}_ new ${TEST_DIR} -q

# Add initializer
cat <<RB > config/initializers/sass_middleware.rb
require 'sass/plugin/rack'
RB

# Start Rails server
bin/rails server

Raises "can't modify frozen Array" error in Rails 5 (RAILS_VERSION=5.0.0.1 ./test.sh), doesn't throw any error in Rails 4 (RAILS_VERSION=4.2.7.1 ./test.sh).

Full stacktrace:

[GEM_PATH]/actionpack-5.0.0.1/lib/action_dispatch/middleware/stack.rb:92:in `delete_if': can't modify frozen Array (RuntimeError)
    from [GEM_PATH]/actionpack-5.0.0.1/lib/action_dispatch/middleware/stack.rb:92:in `delete'
    from [GEM_PATH]/sass-rails-5.0.6/lib/sass/rails/railtie.rb:35:in `block in <class:Railtie>'
    from [GEM_PATH]/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    from [GEM_PATH]/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
    from [GEM_PATH]/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:44:in `each'
    from [GEM_PATH]/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
    from [GEM_PATH]/railties-5.0.0.1/lib/rails/application/finisher.rb:65:in `block in <module:Finisher>'
    from [GEM_PATH]/railties-5.0.0.1/lib/rails/initializable.rb:30:in `instance_exec'
    from [GEM_PATH]/railties-5.0.0.1/lib/rails/initializable.rb:30:in `run'
    from [GEM_PATH]/railties-5.0.0.1/lib/rails/initializable.rb:55:in `block in run_initializers'
    from [RUBY]/tsort.rb:228:in `block in tsort_each'
    from [RUBY]/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from [RUBY]/tsort.rb:431:in `each_strongly_connected_component_from'
    from [RUBY]/tsort.rb:349:in `block in each_strongly_connected_component'
    from [RUBY]/tsort.rb:347:in `each'
    from [RUBY]/tsort.rb:347:in `call'
    from [RUBY]/tsort.rb:347:in `each_strongly_connected_component'
    from [RUBY]/tsort.rb:226:in `tsort_each'
    from [RUBY]/tsort.rb:205:in `tsort_each'
    from [GEM_PATH]/railties-5.0.0.1/lib/rails/initializable.rb:54:in `run_initializers'
    from [GEM_PATH]/railties-5.0.0.1/lib/rails/application.rb:352:in `initialize!'
    from [RAILS]/config/environment.rb:5:in `<top (required)>'
    from [RAILS]/config.ru:3:in `require_relative'
    from [RAILS]/config.ru:3:in `block in <main>'
    from [GEM_PATH]/rack-2.0.1/lib/rack/builder.rb:55:in `instance_eval'
    from [GEM_PATH]/rack-2.0.1/lib/rack/builder.rb:55:in `initialize'
    from [RAILS]/config.ru:in `new'
    from [RAILS]/config.ru:in `<main>'
    from [GEM_PATH]/rack-2.0.1/lib/rack/builder.rb:49:in `eval'
    from [GEM_PATH]/rack-2.0.1/lib/rack/builder.rb:49:in `new_from_string'
    from [GEM_PATH]/rack-2.0.1/lib/rack/builder.rb:40:in `parse_file'
    from [GEM_PATH]/rack-2.0.1/lib/rack/server.rb:318:in `build_app_and_options_from_config'
    from [GEM_PATH]/rack-2.0.1/lib/rack/server.rb:218:in `app'
    from [GEM_PATH]/railties-5.0.0.1/lib/rails/commands/server.rb:59:in `app'
    from [GEM_PATH]/rack-2.0.1/lib/rack/server.rb:353:in `wrapped_app'
    from [GEM_PATH]/railties-5.0.0.1/lib/rails/commands/server.rb:124:in `log_to_stdout'
    from [GEM_PATH]/railties-5.0.0.1/lib/rails/commands/server.rb:77:in `start'
    from [GEM_PATH]/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:90:in `block in server'
    from [GEM_PATH]/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:85:in `tap'
    from [GEM_PATH]/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:85:in `server'
    from [GEM_PATH]/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
    from [GEM_PATH]/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
    from [RAILS]/bin/rails:9:in `require'
    from [RAILS]/bin/rails:9:in `<top (required)>'
    from [GEM_PATH]/spring-1.7.2/lib/spring/client/rails.rb:28:in `load'
    from [GEM_PATH]/spring-1.7.2/lib/spring/client/rails.rb:28:in `call'
    from [GEM_PATH]/spring-1.7.2/lib/spring/client/command.rb:7:in `call'
    from [GEM_PATH]/spring-1.7.2/lib/spring/client.rb:30:in `run'
    from [GEM_PATH]/spring-1.7.2/bin/spring:49:in `<top (required)>'
    from [GEM_PATH]/spring-1.7.2/lib/spring/binstub.rb:11:in `load'
    from [GEM_PATH]/spring-1.7.2/lib/spring/binstub.rb:11:in `<top (required)>'
    from [RUBY]/rubygems/core_ext/kernel_require.rb:55:in `require'
    from [RUBY]/rubygems/core_ext/kernel_require.rb:55:in `require'
    from [RAILS]/bin/spring:13:in `<top (required)>'
    from bin/rails:3:in `load'
    from bin/rails:3:in `<main>'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions