5

I have been facing the NoMethodError: undefined method start_with?' for nil:NilClass error while precompiling assets in production.

This seems to be an issue with uglifier and I am using the following gems:

rails (5.2.2)

uglifier (4.1.9)

sprockets-rails (3.2.1)

therubyracer (0.12.3)

Log trace:

** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke yarn:install (first_time)
** Execute yarn:install
yarn install v1.13.0
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.36s.
** Execute assets:precompile
rake aborted!
NoMethodError: undefined method `start_with?' for nil:NilClass
/usr/lib64/ruby/gems/2.4.0/gems/uglifier-4.1.9/lib/uglifier.rb:225:in `error_message'
/usr/lib64/ruby/gems/2.4.0/gems/uglifier-4.1.9/lib/uglifier.rb:234:in `parse_result'
/usr/lib64/ruby/gems/2.4.0/gems/uglifier-4.1.9/lib/uglifier.rb:216:in `run_uglifyjs'
/usr/lib64/ruby/gems/2.4.0/gems/uglifier-4.1.9/lib/uglifier.rb:168:in `compile'
/usr/lib64/ruby/gems/2.4.0/gems/sprockets-3.7.1/lib/sprockets/compressing.rb:65:in `block in js_compressor='
/usr/lib64/ruby/gems/2.4.0/gems/sprockets-3.7.1/lib/sprockets/legacy_proc_processor.rb:31:in `call'

I checked the similar issue reported here but adding config.assets.js_compressor = Uglifier.new(harmony: true, compress: { unused: false }) to config/environments/production.rb did not resolve the issue.

Any lead to resolve the issue would be highly appreciated. Thanks!

Community
  • 1
  • 1
dp7
  • 6,651
  • 1
  • 18
  • 37
  • Could you provide a longer log trace? Are you sure you don't have that method error somewhere in your application? – Clara Feb 27 '19 at 13:14
  • @Clara : No this method doesn't belong to my application. As the above trace suggests, that method exists in Uglifier gem. – dp7 Feb 27 '19 at 15:45
  • I have the exact same issue, problem comes from the gem. I had to remove `uglifier` from my gemfile, as well as comment out the line `config.assets.js_compressor = :uglifier` from my `config/production.rb` – Alexis Delahaye Jun 13 '19 at 15:00

1 Answers1

1

here is an issue https://github.com/lautis/uglifier/issues/137

always check "issues" on gems page

Igor Kasyanchuk
  • 766
  • 6
  • 12
  • Hi, thanks for your response. I would request you to read the question fully as I have mentioned this link already in the question where it says `I checked the similar issue reported here...` – dp7 Feb 28 '19 at 11:16
  • ok, other solution, fork and clone uglifier gem. Connect it in Gemfile, using gem "uglifier", github: '.....'. And put a change here https://github.com/lautis/uglifier/blob/master/lib/uglifier.rb#L225 and check if object is nil or not – Igor Kasyanchuk Feb 28 '19 at 12:05
  • yeah , result hash looks like this: `{ "error" => {} }` – dp7 Feb 28 '19 at 12:43