Stimulus: IE11 - Error connecting controller - TypeError: Object doesn't support property or method 'matches'

Created on 20 Nov 2018  路  8Comments  路  Source: hotwired/stimulus

Getting this error thrown with a controller, seems to be linked to accessing a target, but unconfirmed.

image

Stripped back my controller to the following code... Console.log('1') fires, the rest is where the error is thrown.

Data-controller is on the body, as it needs to be a site-wide thing.

// Samples Controller
import { Controller } from 'stimulus'

export default class extends Controller {
  static targets = ['counter']

  connect() {
    this.updateCount()
  }

  updateCount() {
    console.log('1')
    console.log(this.counterTargets)
    console.log('2')
  }
}

It seems to stem from this...

Scope.prototype.findAllElements = function (selector) {
        var head = this.element.matches(selector) ? [this.element] : [];
        var tail = this.filterElements(Array.from(this.element.querySelectorAll(selector)));
        return head.concat(tail);
    };

Edit: this.targets.findAll('counter') returns the same error in all controllers.

Most helpful comment

All 8 comments

Browser Support

Stimulus supports all evergreen, self-updating desktop and mobile browsers out of the box.

If your application needs to support older browsers like Internet Explorer 11, include the聽 @stimulus/polyfills 聽package before loading Stimulus.

Are you using that 馃憜?

Doh!!! My bad! Deepest apologies!

I get this issue again, because the @stimulus/polyfills version matcher for element-closest is pulling in 3.0.0, which doesn't work the same / is broken: https://github.com/jonathantneal/closest/issues/25 & https://github.com/jonathantneal/closest/blob/master/CHANGELOG.md

this is incompatible with the latest webpacker which depends on core-js 3 :(

@glaszig did you find a solution?

@chrisokamoto this occured to me while upgrading to the latest webpacker at the time on a rails 5.2 code base. i reverted that upgrade and things work fine.

@chrisokamoto this occured to me while upgrading to the latest webpacker at the time on a rails 5.2 code base. i reverted that upgrade and things work fine.

@glaszig yeah, the same for me. but I don't want to downgrade Rails and Webpacker.. I'll try something else, which include stop using stimulus.. :( it's just a small component in my case.
Thanks for the reply :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

incompletude picture incompletude  路  3Comments

ngan picture ngan  路  3Comments

JanaDeppe picture JanaDeppe  路  4Comments

gerdriesselmann picture gerdriesselmann  路  3Comments

saneef picture saneef  路  4Comments