# When use js\_compressor compile stimulus controller

**URL:** <https://discuss.hotwired.dev/t/when-use-js-compressor-compile-stimulus-controller/2146>\
**Category:** General\
**Created:** [January 27, 2021, 2:55am UTC](https://discuss.hotwired.dev/t/when-use-js-compressor-compile-stimulus-controller/2146 "2021-01-27T02:55:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xing\_Fang](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/xing_fang/32/1537_2.png) [@Xing\_Fang](https://discuss.hotwired.dev/u/Xing_Fang)\
**Post date:** [January 27, 2021, 2:55am UTC](https://discuss.hotwired.dev/t/when-use-js-compressor-compile-stimulus-controller/2146/1 "2021-01-27T02:55:23Z")

</div>

I’m using hotwire-rails with assets pipeline, it works fine when `js_compressor` is off but raised an `Uglifier::Error Unexpected token: keyword (extends) Error ` if `js_compressor` is on. I knew I can’t do [concatenation or transpiling](https://discuss.hotwired.dev/t/installing-turbo-with-the-asset-pipeline/1877/5), but I should be able to do compression?

I knew this should be a Uglifier issue, but all Uglifier solution is suggested pass `harmony: true`, I already did it, event tried `terser`, still got the same error, I can’t figure it out.

```auto
# config/environments/development.rb
config.assets.js_compressor = Uglifier.new(harmony: true) 

```

bundle exec assets:precompile Exception backtrace

```auto
Uglifier::Error: Unexpected token: keyword (extends)
--
 1 import { Controller } from "stimulus"
 2
 => export default class extends Controller {
 4 connect() {
 5 this.element.textContent = "Hello World!"
 6 }
 7 };
/Users/fangxing/.rvm/gems/ruby-2.6.6/gems/uglifier-4.2.0/lib/uglifier.rb:291:in `parse_result'
/Users/fangxing/.rvm/gems/ruby-2.6.6/gems/uglifier-4.2.0/lib/uglifier.rb:221:in `run_uglifyjs'
/Users/fangxing/.rvm/gems/ruby-2.6.6/gems/uglifier-4.2.0/lib/uglifier.rb:166:in `compile'
/Users/fangxing/.rvm/gems/ruby-2.6.6/gems/sprockets-4.0.2/lib/sprockets/compressing.rb:84:in `block in js_compressor='

```

---

<div class="post-metadata">

**Author:** ![Xing\_Fang](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/xing_fang/32/1537_2.png) [@Xing\_Fang](https://discuss.hotwired.dev/u/Xing_Fang)\
**Post date:** [January 28, 2021, 9:44am UTC](https://discuss.hotwired.dev/t/when-use-js-compressor-compile-stimulus-controller/2146/2 "2021-01-28T09:44:11Z")

</div>

Solved by switching to [terser-ruby](https://github.com/ahorek/terser-ruby), and add a class name after the `class` keyword

```auto
export default class Hello extends Controller

```

---

<div class="post-metadata">

**Author:** ![AxelTheGerman](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@AxelTheGerman](https://discuss.hotwired.dev/u/AxelTheGerman)\
**Post date:** [February 15, 2021, 5:54am UTC](https://discuss.hotwired.dev/t/when-use-js-compressor-compile-stimulus-controller/2146/3 "2021-02-15T05:54:50Z")

</div>

@Xing_Fang thank you so much for posting your solution once you figured it out - I ran into the same issue and it doesn’t seem to come up often

---

<div class="post-metadata">

**Author:** ![Xing\_Fang](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/xing_fang/32/1537_2.png) [@Xing\_Fang](https://discuss.hotwired.dev/u/Xing_Fang)\
**Post date:** [March 26, 2021, 1:21am UTC](https://discuss.hotwired.dev/t/when-use-js-compressor-compile-stimulus-controller/2146/4 "2021-03-26T01:21:51Z")

</div>

Don’t need classname anymore, terser team fixed this bug [Error when export default anonymous class with extends · Issue #924 · terser/terser · GitHub](https://github.com/terser/terser/issues/924)
