部署到Heroku:NoMethodError:nil:NilClass的未定义方法'+'

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了部署到Heroku:NoMethodError:nil:NilClass的未定义方法'+'相关的知识,希望对你有一定的参考价值。

我是Rails的新手,但是最近几周我一直在开发一个应用程序,当我部署到Heroku时,该应用程序在开发和生产中一直表现出色。

今天,我对application.css文件进行了一些较小的更改,现在,当我尝试将其部署到Heroku时,出现了“预编译资产失败”错误。使用NoMethodError:nil:NilClass的未定义方法“ +”。运行ruby 2.6.5,Rails 6.0.3.1,PG 1.2.3]

我在下面附上了日志,可能有帮助也可能没有帮助。我显然不了解如何正确调试此错误,因此有关可能导致该错误的原因的建议很棒,但失败了,我应该如何尝试在本地复制此错误并找出原因?

我已经尝试过,但没有成功:

  1. 将application.css文件更改为.scss
  2. config.assets.initialize_on_precompile = false添加到application.rb文件
  3. 恢复到我的上一次成功提交

谢谢!


    Enumerating objects: 78, done.
    Counting objects: 100% (78/78), done.
    Delta compression using up to 8 threads
    Compressing objects: 100% (61/61), done.
    Writing objects: 100% (61/61), 5.07 KiB | 519.00 KiB/s, done.
    Total 61 (delta 46), reused 0 (delta 0)
    remote: Compressing source files... done.
    remote: Building source:
    remote:
    remote: -----> Ruby app detected
    remote: -----> Installing bundler 1.17.3
    remote: -----> Removing BUNDLED WITH version in the Gemfile.lock
    remote: -----> Compiling Ruby/Rails
    remote: -----> Using Ruby version: ruby-2.6.5
    remote:
    remote: ###### WARNING:
    remote:
    remote:        Removing `Gemfile.lock` because it was generated on Windows.
    remote:        Bundler will do a full resolve so native gems are handled properly.
    remote:        This may result in unexpected gem versions being used in your app.
    remote:        In rare occasions Bundler may not be able to resolve your dependencies at all.
    remote:        https://devcenter.heroku.com/articles/bundler-windows-gemfile
    remote:
    remote: -----> Installing dependencies using bundler 1.17.3
    remote:        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4
    remote:        The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64
    -mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
    remote:        Fetching gem metadata from https://rubygems.org/.............
    remote:        Fetching gem metadata from https://rubygems.org/.
    remote:        Resolving dependencies.....
    remote:        Using rake 13.0.1
    remote:        Using concurrent-ruby 1.1.6
    remote:        Using minitest 5.14.1
    remote:        Using thread_safe 0.3.6
    remote:        Using zeitwerk 2.3.0
    remote:        Using builder 3.2.4
    remote:        Using erubi 1.9.0
    remote:        Using mini_portile2 2.4.0
    remote:        Using crass 1.0.6
    remote:        Using rack 2.2.2
    remote:        Using nio4r 2.5.2
    remote:        Fetching websocket-extensions 0.1.5
    remote:        Using mimemagic 0.3.5
    remote:        Using mini_mime 1.0.2
    remote:        Using formtastic_i18n 0.6.0
    remote:        Using method_source 1.0.0
    remote:        Using thor 1.0.1
    remote:        Using kaminari-core 1.2.1
    remote:        Fetching ffi 1.13.0
    remote:        Using tilt 2.0.10
    remote:        Using bcrypt 3.1.13
    remote:        Using msgpack 1.3.3
    remote:        Using bundler 1.17.3
    remote:        Using orm_adapter 0.5.0
    remote:        Using hashids 1.0.5
    remote:        Using pg 1.2.3
    remote:        Using turbolinks-source 5.2.0
    remote:        Fetching i18n 1.8.3
    remote:        Installing websocket-extensions 0.1.5
    remote:        Installing i18n 1.8.3
    remote:        Using tzinfo 1.2.7
    remote:        Using nokogiri 1.10.9
    remote:        Using puma 4.3.5
    remote:        Using rack-test 1.1.0
    remote:        Fetching sprockets 4.0.1
    remote:        Installing sprockets 4.0.1
    remote:        Installing ffi 1.13.0 with native extensions
    remote:        Using warden 1.2.8
    remote:        Using rack-proxy 0.6.5
    remote:        Using marcel 0.3.3
    remote:        Using mail 2.7.1
    remote:        Using bootsnap 1.4.6
    remote:        Using turbolinks 5.2.1
    remote:        Using loofah 2.5.0
    remote:        Using websocket-driver 0.7.2
    remote:        Using activesupport 6.0.3.1
    remote:        Using rails-dom-testing 2.0.3
    remote:        Using rails-html-sanitizer 1.3.0
    remote:        Using globalid 0.4.2
    remote:        Using activemodel 6.0.3.1
    remote:        Using arbre 1.2.1
    remote:        Using jbuilder 2.10.0
    remote:        Using actionview 6.0.3.1
    remote:        Using activejob 6.0.3.1
    remote:        Using activerecord 6.0.3.1
    remote:        Using actionpack 6.0.3.1
    remote:        Using kaminari-actionview 1.2.1
    remote:        Using kaminari-activerecord 1.2.1
    remote:        Using polyamorous 2.3.2
    remote:        Using hashid-rails 1.4.0
    remote:        Using actioncable 6.0.3.1
    remote:        Using activestorage 6.0.3.1
    remote:        Using actionmailer 6.0.3.1
    remote:        Using formtastic 3.1.5
    remote:        Using has_scope 0.7.2
    remote:        Using railties 6.0.3.1
    remote:        Using kaminari 1.2.1
    remote:        Using ransack 2.3.2
    remote:        Using actionmailbox 6.0.3.1
    remote:        Using actiontext 6.0.3.1
    remote:        Using responders 3.0.1
    remote:        Using jquery-rails 4.4.0
    remote:        Using webpacker 4.2.2
    remote:        Using inherited_resources 1.11.0
    remote:        Using devise 4.7.1
    remote:        Using sprockets-rails 3.2.1
    remote:        Using rails 6.0.3.1
    remote:        Fetching sassc 2.4.0
    remote:        Installing sassc 2.4.0 with native extensions
    remote:        Using sassc-rails 2.1.2
    remote:        Using activeadmin 2.7.0
    remote:        Using sass-rails 6.0.0
    remote:        Bundle complete! 18 Gemfile dependencies, 77 gems now installed.
    remote:        Gems in the groups development and test were not installed.
    remote:        Bundled gems are installed into `./vendor/bundle`
    remote:        Post-install message from i18n:
    remote:
    remote:        HEADS UP! i18n 1.1 changed fallbacks to exclude default locale.
    remote:        But that may break your application.
    remote:
    remote:        If you are upgrading your Rails application from an older version of Rails:
    remote:
    remote:        Please check your Rails app for 'config.i18n.fallbacks = true'.
    remote:        If you're using I18n (>= 1.1.0) and Rails (< 5.2.2), this should be
    remote:        'config.i18n.fallbacks = [I18n.default_locale]'.
    remote:        If not, fallbacks will be broken in your app by I18n 1.1.x.
    remote:
    remote:        If you are starting a NEW Rails application, you can ignore this notice.
    remote:
    remote:        For more info see:
    remote:        https://github.com/svenfuchs/i18n/releases/tag/v1.1.0
    remote:
    remote:        Removing i18n (1.8.2)
    remote:        Removing sprockets (4.0.0)
    remote:        Removing websocket-extensions (0.1.4)
    remote:        Removing ffi (1.12.2)
    remote:        Removing sassc (2.3.0)
    remote:        Bundle completed (186.51s)
    remote:        Cleaning up the bundler cache.
    remote:        The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64
    -mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
    remote: -----> Installing node-v10.15.3-linux-x64
    remote: -----> Installing yarn-v1.16.0
    remote: -----> Detecting rake tasks
    remote: -----> Preparing app for Rails asset pipeline
    remote:        Running: rake assets:precompile
    remote:        yarn install v1.16.0
    remote:        [1/4] Resolving packages...
    remote:        [2/4] Fetching packages...
    remote:        info fsevents@1.2.13: The platform "linux" is incompatible with this module.
    remote:        info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
    remote:        [3/4] Linking dependencies...
    remote:        warning " > webpack-dev-server@3.11.0" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
    remote:        warning "webpack-dev-server > webpack-dev-middleware@3.7.2" has unmet peer dependency "webpack@^4.0.0".
    remote:        [4/4] Building fresh packages...
    remote:        Done in 23.47s.
    remote:        yarn install v1.16.0
    remote:        [1/4] Resolving packages...
    remote:        [2/4] Fetching packages...
    remote:        info fsevents@1.2.13: The platform "linux" is incompatible with this module.
    remote:        info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
    remote:        [3/4] Linking dependencies...
    remote:        warning " > webpack-dev-server@3.11.0" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
    remote:        warning "webpack-dev-server > webpack-dev-middleware@3.7.2" has unmet peer dependency "webpack@^4.0.0".
    remote:        [4/4] Building fresh packages...
    remote:        Done in 5.05s.
    remote:        I, [2020-06-05T05:23:48.123557 #791]  INFO -- : Writing /tmp/build_89a8346fedd1ed19bb5329c741888493/public/assets/active_admin-312e30985f3b0561c5db85eaba9b50b1d2c6fcbcff0e0cd5ae0862f13ef86223
    796473.css
    remote:        I, [2020-06-05T05:23:48.123844 #791]  INFO -- : Writing /tmp/build_89a8346fedd1ed19bb5329c741888493/public/assets/active_admin-312e30985f3b0561c5db85eaba9b50b1d2c6fcbcff0e0cd5ae0862f13ef86223
    796473.css.gz
    remote:        I, [2020-06-05T05:23:48.124090 #791]  INFO -- : Writing /tmp/build_89a8346fedd1ed19bb5329c741888493/public/assets/active_admin/print-312e30cf99cbf27fb92065a9eacd28e6fad48fa72cadaf6e0918790e8d
    35b11d8f99f6.css
    remote:        I, [2020-06-05T05:23:48.124270 #791]  INFO -- : Writing /tmp/build_89a8346fedd1ed19bb5329c741888493/public/assets/active_admin/print-312e30cf99cbf27fb92065a9eacd28e6fad48fa72cadaf6e0918790e8d
    35b11d8f99f6.css.gz
    remote:        I, [2020-06-05T05:23:48.124504 #791]  INFO -- : Writing /tmp/build_89a8346fedd1ed19bb5329c741888493/public/assets/manifest-312e3075a11da44c802486bc6f65640aa48a730f0f684c5c07a42ba3cd1735eb3fb0
    70.js
    remote:        I, [2020-06-05T05:23:48.124686 #791]  INFO -- : Writing /tmp/build_89a8346fedd1ed19bb5329c741888493/public/assets/manifest-312e3075a11da44c802486bc6f65640aa48a730f0f684c5c07a42ba3cd1735eb3fb0
    70.js.gz
    remote:        rake aborted!
    remote:        NoMethodError: undefined method `+' for nil:NilClass
    remote:        /tmp/build_89a8346fedd1ed19bb5329c741888493/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.1/lib/sprockets/asset.rb:138:in `etag'
    remote:        /tmp/build_89a8346fedd1ed19bb5329c741888493/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.1/lib/sprockets/asset.rb:67:in `block in digest_path'
    remote:        /tmp/build_89a8346fedd1ed19bb5329c741888493/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.1/lib/sprockets/asset.rb:67:in `sub'
    remote:        /tmp/build_89a8346fedd1ed19bb5329c741888493/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.1/lib/sprockets/asset.rb:67:in `digest_path'
    remote:        /tmp/build_89a8346fedd1ed19bb5329c741888493/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.1/lib/sprockets/manifest.rb:175:in `block in compile'
    remote:        /tmp/build_89a8346fedd1ed19bb5329c741888493/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.1/lib/sprockets/manifest.rb:173:in `each'
    remote:        /tmp/build_89a8346fedd1ed19bb5329c741888493/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.1/lib/sprockets/manifest.rb:173:in `compile'
    remote:        /tmp/build_89a8346fedd1ed19bb5329c741888493/vendor/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:68:in `block (3 levels) in define'
    remote:        /tmp/build_89a8346fedd1ed19bb5329c741888493/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.1/lib/rake/sprocketstask.rb:148:in `with_logger'
    remote:        /tmp/build_89a8346fedd1ed19bb5329c741888493/vendor/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
    remote:        /tmp/build_89a8346fedd1ed19bb5329c741888493/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
    remote:        Tasks: TOP => assets:precompile
    remote:        (See full trace by running task with --trace)
    remote:
    remote:  !
    remote:  !     Precompiling assets failed.
    remote:  !
    remote:  !     Push rejected, failed to compile Ruby app.
    remote:
    remote:  !     Push failed
    remote: Verifying deploy...
    remote:
    remote: !       Push rejected to ...
    remote:

答案

这里是可能的解决方案:尚未尝试,但是您应该看一下。

以上是关于部署到Heroku:NoMethodError:nil:NilClass的未定义方法'+'的主要内容,如果未能解决你的问题,请参考以下文章

使用Heroku部署Node.js应用程序 - 启动脚本

如何将nodejs和vuejs部署到heroku

将nodejs部署到heroku

将应用程序部署到 Heroku 后无法推送到 Github

MERN 应用程序在部署到 Heroku 时无法运行“heroku-postbuild”脚本

无法将python代码部署到heroku